MCPAgent API Reference
stream
(AgentAction, str)
tuples, followed by the final result as a string.
Parameters:
query
(str): The query to executemax_steps
(int, optional): Maximum number of steps to takemanage_connector
(bool): Whether to handle connector lifecycleexternal_history
(list[BaseMessage], optional): External conversation history
(AgentAction, str)
: Intermediate steps containing the action and observationstr
: Final result string
run
query
(str): The query to executemax_steps
(int, optional): Maximum number of steps to takemanage_connector
(bool): Whether to handle connector lifecycleexternal_history
(list[BaseMessage], optional): External conversation historyoutput_schema
(type[T], optional): Pydantic model for structured output. If provided, the agent will return an instance of this model.
str
|T
: The final result as a string, or a Pydantic model instance ifoutput_schema
is provided.
astream
query
(str): The query to executemax_steps
(int, optional): Maximum number of steps to takemanage_connector
(bool): Whether to handle connector lifecycleexternal_history
(list[BaseMessage], optional): External conversation history
str
: Streaming chunks of the agent’s output
Method Comparison
Method | Use Case | Output Type | Granularity |
---|---|---|---|
stream() | Step-by-step workflow tracking | Steps + final result | Tool-level |
run() | Simple execution | Final result only | Complete |
astream() | Real-time chat interfaces | Streaming chunks | Token-level |
Conversation Memory
Methods for managing the agent’s conversation history.get_conversation_history
BaseMessage
objects. This is useful for inspecting the agent’s memory or for passing it to another agent.
Returns:
list[BaseMessage]
: The list of messages in the conversation history.