Skip to content

Agent Definitions

Agent

Bases: AgentMeta

The Agent class is a concrete implementation of an AI agent with tool-calling capabilities, inheriting from AgentMeta. It integrates a language model, tools, memory, and flow management to process queries, execute tools, and maintain conversational context.

Methods:

Name Description
ainvoke

Answer the user query asynchronously with continuous tool calling capability.

invoke

Answer the user query synchronously with continuous tool calling capability.

stream

Answer the user query by streaming with continuous tool calling capability. Yields streamed responses or the final tool execution result.

save_memory

Save the tool message to the memory

register_tools

Register a list of tools

ainvoke async

ainvoke(query: str, is_save_memory: bool = False, user_id: str = 'unknown_user', token: str = None, secret_key: str = None, max_iterations: int = 10, **kwargs) -> Any

Answer the user query asynchronously with continuous tool calling capability. Args: query (str): The input query or task description provided by the user. is_save_memory (bool, optional): Flag to determine if the conversation should be saved to memory. Defaults to False. user_id (str, optional): Identifier for the user making the request. Defaults to "unknown_user". token (str, optional): Authentication token for the user. Defaults to None. secret_key (str, optional): Secret key for authentication. Defaults to None. max_iterations (int, optional): Maximum number of tool call iterations to prevent infinite loops. Defaults to 10. **kwargs: Additional keyword arguments, including an optional config dictionary for graph execution.

Returns:

Name Type Description
Any Any

The result of the tool execution, LLM response, or None if an error occurs during tool execution.

Raises:

Type Description
JSONDecodeError

If the tool data cannot be parsed as valid JSON.

KeyError

If required keys are missing in the tool data.

ValueError

If the tool data is invalid or cannot be processed.

invoke

invoke(query: str, is_save_memory: bool = False, user_id: str = 'unknown_user', token: str = None, secret_key: str = None, max_iterations: int = 10, **kwargs) -> Any

Answer the user query synchronously with continuous tool calling capability.

Parameters:

Name Type Description Default
query str

The input query or task description provided by the user.

required
is_save_memory bool

Flag to determine if the conversation should be saved to memory. Defaults to False.

False
user_id str

Identifier for the user making the request. Defaults to "unknown_user".

'unknown_user'
token str

Authentication token for the user. Defaults to None.

None
secret_key str

Secret key for authentication. Defaults to None.

None
max_iterations int

Maximum number of tool call iterations to prevent infinite loops. Defaults to 10.

10
**kwargs

Additional keyword arguments, including an optional config dictionary for graph execution.

{}

Returns:

Name Type Description
Any Any

The result of the tool execution, LLM response, or None if an error occurs during tool execution.

Raises:

Type Description
JSONDecodeError

If the tool data cannot be parsed as valid JSON.

KeyError

If required keys are missing in the tool data.

ValueError

If the tool data is invalid or cannot be processed.

stream

stream(query: str, is_save_memory: bool = False, user_id: str = 'unknown_user', token: str = None, secret_key: str = None, max_iterations: int = 10, **kwargs) -> AsyncGenerator[Any, None]

Answer the user query by streaming with continuous tool calling capability. Yields streamed responses or the final tool execution result.

Parameters:

Name Type Description Default
query str

The input query or task description provided by the user.

required
is_save_memory bool

Flag to determine if the conversation should be saved to memory. Defaults to False.

False
user_id str

Identifier for the user making the request. Defaults to "unknown_user".

'unknown_user'
token str

Authentication token for the user. Defaults to None.

None
secret_key str

Secret key for authentication. Defaults to None.

None
max_iterations int

Maximum number of tool call iterations to prevent infinite loops. Defaults to 10.

10
**kwargs

Additional keyword arguments, including an optional config dictionary for graph execution.

{}

Returns:

Name Type Description
Any AsyncGenerator[Any, None]

The result of the tool execution, LLM response, or None if an error occurs during tool execution.

Raises:

Type Description
JSONDecodeError

If the tool data cannot be parsed as valid JSON.

KeyError

If required keys are missing in the tool data.

ValueError

If the tool data is invalid or cannot be processed.

save_memory

save_memory(message: Union[ToolMessage, AIMessage], user_id: str = 'unknown_user') -> None

Save the tool message to the memory

register_tools

register_tools(tools: List[str]) -> Any

Register a list of tools