Skip to content

run()

Starts a streaming agent run.

Signature

typescript
function run(prompt: string, config: RunConfig): Promise<AgentRun>

Parameters

prompt

  • Type: string
  • The user message to send to the agent.

config

PropertyTypeRequiredDescription
provider"claude" | "codex" | "kimi"YesBackend provider
agentAgentDefYesThe agent definition
agentsRecord<string, AgentDef>NoAgent map for handoffs
mcpServersRecord<string, McpServerConfig>NoMCP server configs
providerOptionsRecord<string, unknown>NoProvider-specific options
workDirstringNoWorking directory
maxTurnsnumberNoLimit tool-use turns
signalAbortSignalNoCancellation signal

Returns

Promise<AgentRun> with the following properties:

PropertyTypeDescription
streamAsyncGenerator<StreamChunk>Stream of events
chat(message: string) => AsyncGenerator<StreamChunk>Send a follow-up message
close() => Promise<void>Clean up resources

Example

typescript
import { defineAgent, run } from "one-agent-sdk";

const agent = defineAgent({
  name: "assistant",
  description: "A helpful assistant",
  prompt: "You are a helpful assistant.",
});

const { stream, chat, close } = await run("Hello!", {
  provider: "claude",
  agent,
});

for await (const chunk of stream) {
  if (chunk.type === "text") {
    process.stdout.write(chunk.text);
  }
}

await close();