Agent Loop
The agent stores conversation state in memory for the lifetime of the Agent instance.
For each prompt, it:
- Adds the prompt as a user message.
- Calls the configured model client.
- Emits the assistant response.
- Executes any
tool_useblocks. - Adds
tool_resultblocks as a user message. - Repeats until the assistant returns no tool calls.
- Emits a final
resultmessage.
const agent = createAgent({ apiKey: process.env.DEEPSEEK_API_KEY, baseURL: "https://api.deepseek.com/anthropic", model: "deepseek-v4-flash", maxTurns: 10,});
await agent.prompt("Remember that my project is an SDK.");const result = await agent.prompt("What kind of project is this?");maxTurns protects the host application from infinite tool loops. When the limit is reached, the SDK emits a result with subtype: "error_max_turns".