.invoke()
/ await .ainvoke()
for full responses, or .stream()
/ .astream()
for incremental streaming output. This section explains how to provide input, interpret output, enable streaming, and control execution limits.
.invoke()
or .stream()
await .invoke()
or for await
with .stream()
messages
as an input. Therefore, agent inputs and outputs are stored as a list of messages
under the messages
key in the agent state.
messages
key. Supported formats are:
Format | Example |
---|---|
String | {"messages": "Hello"} — Interpreted as a HumanMessage |
Message dictionary | {"messages": {"role": "user", "content": "Hello"}} |
List of messages | {"messages": [{"role": "user", "content": "Hello"}]} |
With custom state | {"messages": [{"role": "user", "content": "Hello"}], "user_name": "Alice"} — If using a custom state definition |
messages
is converted to a HumanMessage. This behavior differs from the prompt
parameter in createReactAgent
, which is interpreted as a SystemMessage when passed as a string.messages
: A list of all messages exchanged during execution (user input, assistant replies, tool invocations).structuredResponse
if structured output is configured.GraphRecursionError
. You can configure recursionLimit
at runtime or when defining agent via .withConfig()
: