TypeScript agents
Agents contracts and source references for TypeScript.
AgentConfig is an interface, not a class. Pass { name, model } to new ToolLoopAgent. Call await agent.initialize() before run(), read output.finalText, and terminate the instance when finished. agentDid is optional. The default approval handler is AutoApprove; select an explicit policy before exposing tools with side effects.
A bounded run
This complete function accepts a model already configured by the caller. No tools are registered. Supply a model supported by your application and handle the returned error or exception at the caller. This example does not provision provider credentials, identity or deployment.
import type { LanguageModel } from '@forge-sdk/core';
import { ToolLoopAgent } from '@forge-sdk/agent';
import { DenyAll } from '@forge-sdk/tool';
export async function runAgent(model: LanguageModel, prompt: string) {
const agent = new ToolLoopAgent({
name: 'reader',
model,
maxIterations: 3,
approvalHandler: new DenyAll('No tools are authorized for this run'),
});
await agent.initialize();
try {
const output = await agent.run(prompt);
return output.finalText;
} finally {
await agent.terminate();
}
}TypeScript reference
Each reference records the source path, hash and declaration inventory for this language. Start at the import boundary before using a symbol found in a deeper implementation file.
Lifecycle and failures
Choose finite iteration and token budgets, handle generation and execution failures, and release resources on termination. Inspect the returned usage and completion state before recording a successful run. The SDK health/lifecycle object describes local runtime state; it is not a deployment health check.