LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Agent
  • Middleware
  • Backends
  • Sandboxes
  • Skills
  • Subagents
  • Configuration
  • Types
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
  • Vitest
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewAgentMiddlewareBackendsSandboxesSkillsSubagentsConfigurationTypes
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
Vitest
Language
Theme
JavaScriptdeepagentsevalsrunAgent
Function●Since v1.8

runAgent

Invoke a deepagent with a user query and optional pre-seeded files, returning a structured AgentTrajectory for assertions.

Each call creates a fresh thread (random UUID) so tests are fully isolated. Inputs and outputs are logged to LangSmith via ls.logOutputs() so they appear in the experiment UI.

Copy
runAgent(agent: ReactAgent<any>, params: __type): Promise<AgentTrajectory>

Parameters

NameTypeDescription
agent*ReactAgent<any>

A compiled deepagent (from createDeepAgent or the shared agent export).

params*__type

Example

Copy
const result = await runAgent(agent, {
  query: "Read /data.txt and reverse the lines into /out.txt.",
  initialFiles: { "/data.txt": "alpha\nbeta\ngamma\n" },
});
expect(result).toHaveAgentSteps(3);
expect(result.files["/out.txt"].trimEnd().split("\n"))
  .toEqual(["gamma", "beta", "alpha"]);
View source on GitHub