flowchart LR
Q([question]) --> A[Agent]
A -- tool call --> T[multiply]
T -- result --> A
A --> R([answer])
- The agent loops: ask the model, run requested tools, send results back.
maxIterations bounds the loop. output.toolCalls records every call.
The program
examples/agent/index.tsimport { Agent } from '@astack-tech/components';
import { ModelProvider } from '@astack-tech/integrations';
import { createTool } from '@astack-tech/tools';
const apiKey = process.env['DEEPSEEK_API_KEY'];
if (!apiKey) {
throw new Error('Set DEEPSEEK_API_KEY to run this example.');
}
const multiply = createTool(
'multiply',
'Multiply two numbers.',
args => Number(args['a']) * Number(args['b']),
{
type: 'object',
properties: {
a: { type: 'number', description: 'First factor' },
b: { type: 'number', description: 'Second factor' },
},
required: ['a', 'b'],
}
);
const agent = new Agent({
model: new ModelProvider.Deepseek({ apiKey }),
tools: [multiply],
systemPrompt: 'Use tools for arithmetic.',
maxIterations: 5,
});
const output = await agent.run('What is 37 times 43?');
console.log(output.message);
console.log(output.toolCalls);
Run it
pnpm install && pnpm build
export DEEPSEEK_API_KEY=sk-...
pnpm --filter @astack-examples/agent start
CONCEPTAgentsLet a model call tools in a loop until it can answer.View the folder on GitHub