Single Agent
An agent is a loop. It calls tools, reads what comes back, and decides what to do next until the work is done or it hits maxTurns. This is the type to reach for when a job needs to look things up or do things rather than just answer.
Options#
Beyond the shared options:
| Option | Type | Default | Notes |
|---|---|---|---|
instructions | string | - | Task-level guidance, alongside systemPrompt |
maxTurns | number | - | Cap on loop iterations |
permissionMode | 'auto' | 'bypass' | 'default' | 'plan' | auto | How tool permissions are resolved |
deadlineMs | number | none | Execution deadline; runs are unbounded by default |
contextWindow | number | 250000 | Working context size |
tools | readonly AgentTool[] | - | Handlers that run in your process |
toolAllowlist | readonly string[] | derived | See Tools |
maxTools | number | - | Cap on tools exposed to the model |
skills | readonly AgentSkill[] | - | See Skills |
mcpServers | readonly AgentMcpServer[] | - | See MCP |
imageModel | string | - | Enables image understanding |
outputs | readonly (AgentOutput | string)[] | - | Files to produce |
maxOutputInlineBytes | number | 262144 | Limit for output content projected inline into the result |
A worker agent#
import { createAgent } from '@coresourceai/sdk';
const worker = createAgent({
type: 'agent',
systemPrompt: 'You maintain the billing service.',
instructions: 'Prefer the smallest change that fixes the issue.',
model: 'deepseek/deepseek-v4-flash',
maxTurns: 24,
deadlineMs: 10 * 60 * 1000,
outputs: ['patch.diff']
});
const result = await worker.run('Fix the currency rounding bug in refunds.');
console.log(result.status, result.text);
await worker.close();systemPrompt versus instructions#
Both reach the model, and the distinction is worth keeping:
systemPromptis who the agent is. Its role, its standards, what it always does. It is the same across every run of this definition.instructionsis task-level guidance layered on top. Use it for the policy that applies to this deployment rather than to the agent's identity.
If you only use one, use systemPrompt.
Bounding the loop#
Two independent options can bound a run:
maxTurns caps loop iterations. Set it according to the number of tool-use and reasoning cycles your task permits.
deadlineMs sets an execution deadline. Runs have no deadline by default. A run that reaches the configured deadline can end as expired.
import { createAgent } from '@coresourceai/sdk';
const responder = createAgent({
type: 'agent',
systemPrompt: 'Answer support questions from the knowledge base.',
// A person is waiting. Fail fast rather than run long.
maxTurns: 6,
deadlineMs: 30_000
});
const result = await responder.run('Does the Pro plan include SSO?');
console.log(result.status);
await responder.close();Your tool handlers see the deadline too, as context.deadlineAt. See writing custom tools.
