Skip to content

Agent

An agent, or one of its conversations. Returned by wardrik.agent.

  • Most methods make one request, to the agent.* operation of the same name.
  • stream and reply also follow the run that answers a message.
  • Methods that can act on a conversation act on conversation.
readonly agent: string;

The agent's ID.

AgentOperations.agent


readonly conversation: string | undefined;

The conversation the methods act on. undefined for the agent's own history.

AgentOperations.conversation

stream(input, options?): AsyncGenerator<WardrikEvent>;

Sends a message and yields the events of the run that answers it, until the run ends.

for await (const event of agent.stream("What's on fire?")) {
if (event.type === "wardrik.message.delta") process.stdout.write(event.data.delta);
if (event.type === "wardrik.run.interrupted") {
for (const interrupt of event.data.interrupts) await agent.approve(interrupt.id);
}
}

An interrupted run carries on, on the same stream, once each interrupt is approved or denied.

Parameter Type
input string | Ask
options? StreamAskOptions

AsyncGenerator<WardrikEvent>


reply(input, options?): Promise<Reply>;

Sends a message and resolves when the run that answers it ends or waits on a person.

const reply = await agent.reply("What's on fire?");
if (reply.status === "completed") console.log(reply.text);
Parameter Type
input string | Ask
options? StreamAskOptions

Promise<Reply>


read(options?): Promise<AgentSnapshot>;

Read what an agent is doing now.

Parameter Type
options? CallOptions

Promise<AgentSnapshot>

AgentOperations.read


define(input?, options?): Promise<AgentSnapshot>;

Define an agent.

Starts the agent the definition describes, or brings the one running to it from its next turn. A definition put again replaces the last. A key nothing here supports yet answers not_supported, naming it.

Acts on the agent, never a conversation.

Parameter Type
input? AgentDefinition
options? CallOptions

Promise<AgentSnapshot>

AgentOperations.define


forget(options?): Promise<void>;

Forget an agent.

Acts on the agent, never a conversation.

Parameter Type
options? CallOptions

Promise<void>

AgentOperations.forget


ask(input, options?): Promise<{
id: string;
cursor: string;
}>;

Send an agent a message.

Parameter Type
input Ask
options? CallOptions

Promise<{ id: string; cursor: string; }>

AgentOperations.ask


decide(input, options?): Promise<object[]>;

Approve or reject the calls an agent waits on.

The decisions are taken together and recorded as the caller's. A rejection's reason is what the model is told in place of the call's answer. An approval's note is what it reads beside the answer.

Parameter Type
input Decisions
options? CallOptions

Promise<object[]>

AgentOperations.decide


authorization(interrupt, options?): Promise<Authorization>;

Read where a person authorizes a call.

Parameter Type
interrupt string
options? CallOptions

Promise<Authorization>

AgentOperations.authorization


cancel(options?): Promise<void>;

Stop what an agent is doing.

Parameter Type
options? CallOptions

Promise<void>

AgentOperations.cancel


events(input?, options?): Promise<Events>;

Read an agent's log.

Parameter Type Description
input? { types?: string[]; after?: string; limit?: number; } -
input.types? string[] The event types to read, as wardrik.run.completed, given once for each. Every type where left out. A wardrik.events.dropped comes whatever the types.
input.after? string The cursor to read after: a page's next, the id of an event a stream gave, or a snapshot's cursor.
input.limit? number How many to read, 100 unless set.
options? CallOptions -

Promise<Events>

AgentOperations.events


streamEvents(input?, options?): EventStream;

Like events, then follows each new event as it's written. Starts after after, or at the end of the log. See EventStream.

Parameter Type Description
input? { types?: string[]; after?: string; } -
input.types? string[] The event types to read, as wardrik.run.completed, given once for each. Every type where left out. A wardrik.events.dropped comes whatever the types.
input.after? string The cursor to read after: a page's next, the id of an event a stream gave, or a snapshot's cursor.
options? StreamOptions -

EventStream

AgentOperations.streamEvents


timeline(options?): Promise<Timeline>;

Read an agent's conversation as a person reads it.

Parameter Type
options? CallOptions

Promise<Timeline>

AgentOperations.timeline


runs(options?): Promise<Runs>;

Read what an agent's runs did and cost.

Parameter Type
options? CallOptions

Promise<Runs>

AgentOperations.runs


approve(
interrupt,
input?,
options?
): Promise<object[]>;

Approve a call an agent waits on.

agent.decide with one approval. Recorded as the caller's.

Parameter Type
interrupt string
input? Approve
options? CallOptions

Promise<object[]>

AgentOperations.approve


deny(
interrupt,
input?,
options?
): Promise<object[]>;

Reject a call an agent waits on.

agent.decide with one rejection. Recorded as the caller's.

Parameter Type
interrupt string
input? Deny
options? CallOptions

Promise<object[]>

AgentOperations.deny


definition(options?): Promise<DefinitionRead>;

Read an agent's definition.

Acts on the agent, never a conversation.

Parameter Type
options? CallOptions

Promise<DefinitionRead>

AgentOperations.definition


spawn(options?): Promise<AgentSummary>;

Start an agent.

Acts on the agent, never a conversation.

Parameter Type
options? CallOptions

Promise<AgentSummary>

AgentOperations.spawn


stop(options?): Promise<AgentSummary>;

Stop an agent.

Parameter Type
options? CallOptions

Promise<AgentSummary>

AgentOperations.stop


clear(options?): Promise<AgentSnapshot>;

Clear an agent's history.

Empties its history. The agent, its definition and its other conversations stay. Answers conflict while it runs a turn or waits on a person.

Parameter Type
options? CallOptions

Promise<AgentSnapshot>

AgentOperations.clear


calls(options?): Promise<object[]>;

List the tool calls an agent is running.

Answers not_found while the agent sleeps.

Parameter Type
options? CallOptions

Promise<object[]>

AgentOperations.calls


kill(call, options?): Promise<void>;

Stop one tool call.

Parameter Type
call string
options? CallOptions

Promise<void>

AgentOperations.kill


triggerSet(
trigger,
input?,
options?
): Promise<TriggerDefinition>;

Set one of an agent's triggers.

Sets or changes one trigger of an agent with a definition, which keeps it; not_found where it has none. A trigger whose every and timezone stay keeps its next run.

Acts on the agent, never a conversation.

Parameter Type
trigger string
input? TriggerDefinition
options? CallOptions

Promise<TriggerDefinition>

AgentOperations.triggerSet


triggerRemove(trigger, options?): Promise<TriggerDefinition>;

Remove one of an agent's triggers.

Acts on the agent, never a conversation.

Parameter Type
trigger string
options? CallOptions

Promise<TriggerDefinition>

AgentOperations.triggerRemove


move(input, options?): Promise<AgentSummary>;

Move an agent to another node.

Starts the agent again on node, as it was. A turn it's taking ends, and what it waits on is abandoned, so ask it again once it's moved.

Parameter Type
input Node
options? CallOptions

Promise<AgentSummary>

AgentOperations.move