Skip to content

Agent API ​

Agent.builder() ​

Returns a new AgentBuilder instance.

ts
const builder = Agent.builder();

AgentBuilder Methods ​

All methods return this for chaining.

MethodTypeDescription
.setName(name)stringAgent name, used in traces and handoffs
.setProvider(provider)IModelProviderRequired. The LLM provider
.setInstructions(text)stringSystem prompt
.tool(tool)IToolRegister a tool (chainable)
.setMemory(adapter, sessionId)IMemoryAdapter, stringEnable session persistence
.addInputGuardrail(g)IInputGuardrailAdd input guardrail
.addOutputGuardrail(g)IOutputGuardrailAdd output guardrail
.addToolGuardrail(g)IToolGuardrailAdd tool guardrail
.setOutputSchema(schema, retries?)IOutputSchema, numberStructured output validation
.addHandoffTarget(target)HandoffTargetRegister a handoff target agent
.setTimeout(ms)numberAbort run after N milliseconds
.setMaxIterations(n)numberMax LLM calls per run (default: 30)
.setStuckLoopThreshold(n)numberStuck-loop detection window (default: 4)
.build()—Returns the configured Agent instance

Agent Methods ​

MethodReturnsDescription
run(query)Promise<IMessage[] | string | undefined>Execute the agent
getLastTrace()ITrace | nullTrace from the last run
on(event, handler)thisSubscribe to a typed event
off(event, handler)thisUnsubscribe
attachInterceptor(fn)thisSugar over on("step", ...)
printSystemPrompt()voidPrint compiled system prompt

run() Return Value ​

ResultMeaning
IMessage[]Run completed — full message history
stringBlocked by guardrail, timeout, or loop
undefinedMax iterations reached without OUTPUT

Released under the MIT License.