import ComposeSDK from "@compose-market/sdk";
const sdk = new ComposeSDK({
userAddress: "0xYourWalletAddress",
chainId: 43113,
});
const agentWallet = "0xa7abfd271130c3ee5c8f8862a123f3697e75af0d";
const threadId = "support-42";
// 1. Recall — get a ready-to-inject context block
const context = await sdk.memory.context("Where did we leave the refund?", {
agentWallet,
userAddress: "0xYourWalletAddress",
threadId,
});
// 2. Run the turn, passing the context into the agent's system prompt
const stream = sdk.agent.stream({
agentWallet,
message: "Where did we leave the refund?",
threadId,
});
let assistantText = "";
for await (const event of stream) {
if (event.type === "text-delta") assistantText += event.delta;
}
// 3. Persist the turn (fire-and-forget)
await sdk.memory.recordTurn({
agentWallet,
userAddress: "0xYourWalletAddress",
threadId,
userMessage: "Where did we leave the refund?",
assistantMessage: assistantText,
model: "gpt-4o",
totalTokens: 480,
});
// 4. Optionally extract a durable fact
await sdk.memory.remember({
agentWallet,
userAddress: "0xYourWalletAddress",
threadId,
content: "The user is waiting on a refund for order #1183.",
type: "fact",
retention: "pinned",
confidence: 0.9,
});