Executes the agent with the given state and returns the final state after all processing.
This method runs the agent's entire workflow synchronously, including:
invoke(
state: InvokeStateParameter<Types>,
config: InvokeConfiguration<InferContextInput<Types["Context"] extends InteropZodObject | AnyAnnotationRoot any[any] : AnyAnnotationRoot> InferMiddlewareContextInputs<Types["Middleware"]>>
): Promise<MergedAgentState<Types>>| Name | Type | Description |
|---|---|---|
state* | InvokeStateParameter<Types> | The initial state for the agent execution. Can be:
|
config | InvokeConfiguration<InferContextInput<Types["Context"] extends InteropZodObject | AnyAnnotationRoot ? any[any] : AnyAnnotationRoot> & InferMiddlewareContextInputs<Types["Middleware"]>> | Optional runtime configuration including: |
const agent = new ReactAgent({
llm: myModel,
tools: [calculator, webSearch],
responseFormat: z.object({
weather: z.string(),
}),
});
const result = await agent.invoke({
messages: [{ role: "human", content: "What's the weather in Paris?" }]
});
console.log(result.structuredResponse.weather); // outputs: "It's sunny and 75°F."