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
JavaScriptdeepagentsevalsgetFinalText
Function●Since v1.8

getFinalText

Extract the text content of the last step in a trajectory.

Returns an empty string when the trajectory has no steps or the final message has non-string content (e.g. a content-block array).

Copy
getFinalText(trajectory: AgentTrajectory): string

Parameters

NameTypeDescription
trajectory*AgentTrajectory

Example

Copy
const result = await runAgent(agent, { query: "What is 2+2?" });
expect(getFinalText(result).trim()).toBe("4");
View source on GitHub