.agents/skills/cline-sdk/references/agent/REFERENCE.md
The Agent class (also exported as AgentRuntime) is the lightweight, stateless agent loop from @cline/agents. It handles the core iteration cycle: send messages to an LLM, execute tool calls, collect results, and repeat until the task is done.
| Use Agent when... | Use ClineCore instead when... |
|---|---|
| You want a simple agent with custom tools | You need built-in tools (bash, editor, etc.) |
| You want minimal dependencies | You need session persistence |
| You need browser compatibility | You need config discovery from .cline/ |
| You're building a stateless worker | You need multi-process session sharing |
| You want full control over the runtime | You want batteries-included setup |
import { Agent } from "@cline/sdk"
const agent = new Agent({
providerId: "anthropic",
modelId: "claude-sonnet-4-6",
apiKey: process.env.ANTHROPIC_API_KEY,
systemPrompt: "You are a helpful assistant.",
tools: [],
})
const result = await agent.run("What is the capital of France?")
console.log(result.outputText)
The Agent operates in a loop:
The agent is stateless in the sense that it does not persist anything to disk. Conversation history is held in memory and can be accessed via snapshot().
new Agent(config) or createAgent(config) - Create an agentagent.run(input) - Start a run with user inputagent.continue(input?) - Continue an existing conversationagent.abort(reason?) - Cancel an active runagent.subscribe(listener) - Listen to streaming eventsagent.snapshot() - Get current runtime stateagent.restore(messages) - Replace message historySee api.md for full API details.
const agent = new Agent({
providerId: "anthropic",
modelId: "claude-sonnet-4-6",
systemPrompt: "You are a helpful assistant.",
tools: [],
})
const first = await agent.run("What is 2 + 2?")
console.log(first.outputText)
const second = await agent.continue("Now multiply that by 3")
console.log(second.outputText)
Use agent.hasRun to check if a run has already been executed, which determines whether to call run() or continue().
Use agent.subscribe() to stream events in real time. Register the listener before calling run() to avoid missing early events.
There is no top-level onEvent field on the Agent config. For an async alternative, use hooks.onEvent (see api.md and gotchas.md).
const agent = new Agent({
providerId: "anthropic",
modelId: "claude-sonnet-4-6",
systemPrompt: "You are a helpful assistant.",
tools: [],
})
agent.subscribe((event) => {
if (event.type === "assistant-text-delta") {
process.stdout.write(event.text)
}
})
const result = await agent.run("What is the capital of France?")
See events/REFERENCE.md for the full event type catalog.
api.md - Full Agent API referencepatterns.md - Common patterns and best practicesgotchas.md - Pitfalls and debugging../tools/REFERENCE.md - Creating custom tools../events/REFERENCE.md - Event system details../providers/REFERENCE.md - Provider configuration