Agents
Agents provide an agentic loop that automatically handles tool execution, enabling autonomous task completion.
Overview
The Agent class implements a complete agentic workflow:
Send prompt to LLM
LLM may request tool calls
Execute tools automatically
Send results back to LLM
Repeat until task complete or limits reached
Creating an Agent
import { AgenticWork } from '@agentic-work/sdk';
const aw = new AgenticWork({
apiEndpoint: 'https://api.agenticwork.io',
authToken: process.env.AGENTICWORK_TOKEN
});
await aw.init();
const agent = aw.createAgent({
model: 'gpt-4o',
systemPrompt: 'You are a helpful coding assistant.',
tools: aw.getMCPTools(),
maxIterations: 10,
maxToolCalls: 25,
onToolCall: (tc) => console.log('Tool called:', tc.name),
onToolResult: (tr) => console.log('Tool result:', tr.content.slice(0, 100)),
onText: (text) => process.stdout.write(text)
});Configuration Options
model
string
Required
LLM model to use
systemPrompt
string
Built-in
Custom system prompt
tools
Tool[]
[]
Tools available to the agent
maxIterations
number
10
Maximum LLM call rounds
maxToolCalls
number
25
Maximum total tool executions
onToolCall
function
-
Callback when tool is invoked
onToolResult
function
-
Callback when tool completes
onText
function
-
Callback for each text chunk
Running an Agent
Streaming Execution
Non-Streaming Execution
Agent Result
The execute() method returns an AgentResult:
Using Platform MCP Tools
Adding Custom Tools
Tool Context
Tools receive a context object with useful utilities:
Use context in tool execution:
Removing Tools
Updating Agent Configuration
Default System Prompt
If no system prompt is provided, agents use:
Callbacks for Observability
Error Handling
Best Practices
Set appropriate limits - Adjust
maxIterationsandmaxToolCallsbased on task complexityUse callbacks - Monitor agent progress with
onToolCallandonToolResultProvide clear prompts - Specific prompts lead to better results
Filter tools - Only provide tools relevant to the task
Handle errors - Implement proper error handling for production use
Last updated