agent
Module Contents
Classes
Agent is the basic unit of the system. It is responsible for |
|
Asynchronous variant of the Agent class |
|
Component that makes agent calling output a streaming response. |
|
Component that makes asynchronous agent calling output a streaming response. |
|
Streaming variant of the Agent class |
|
Streaming variant of the AsyncAgent class |
|
Sequential is an agent container that forwards messages to each agent |
|
Sequential is an agent container that forwards messages to each agent |
|
Streaming variant of the Sequential class |
|
Streaming variant of the AsyncSequential class |
|
Agent is the basic unit of the system. It is responsible for |
|
Agent is the basic unit of the system. It is responsible for |
- class lagent.agents.agent.Agent(llm=None, template=None, memory=dict(type=Memory), output_format=None, aggregator=dict(type=DefaultAggregator), name=None, description=None, hooks=None)
Agent is the basic unit of the system. It is responsible for communicating with the LLM, managing the memory, and handling the message aggregation and parsing. It can also be extended with hooks
- 参数:
llm (Union[BaseLLM, Dict]) – The language model used by the agent.
template (Union[PromptTemplate, str]) – The template used to format the messages.
memory (Dict) – The memory used by the agent.
output_format (Dict) – The output format used by the agent.
aggregator (Dict) – The aggregator used by the agent.
name (Optional[str]) – The name of the agent.
description (Optional[str]) – The description of the agent.
hooks (Optional[Union[List[Dict], Dict]]) – The hooks used by the agent.
- 返回:
The response message.
- 返回类型:
- name = 'Agent'
- llm: lagent.llms.BaseLLM = None
- memory: lagent.memory.MemoryManager
- output_format: lagent.prompts.parsers.StrParser = None
- template = None
- description = None
- aggregator: lagent.agents.aggregator.DefaultAggregator
- update_memory(message, session_id=0)
- forward(*message, session_id=0, **kwargs)
- 参数:
message (lagent.schema.AgentMessage) –
- 返回类型:
Union[lagent.schema.AgentMessage, str]
- state_dict(session_id=None, prefix='', destination=None)
- 返回类型:
Dict
- load_state_dict(state_dict, session_id=0)
- 参数:
state_dict (Dict) –
- register_hook(hook)
- 参数:
hook (Callable) –
- reset(session_id=0, keypath=None, recursive=False)
- 参数:
keypath (Optional[str]) –
recursive (bool) –
- get_messages(session_id=0, keypath=None)
Get OpenAI format messages from memory.
- 参数:
session_id (int) – The session id of the memory.
keypath (Optional[str]) – The keypath of the sub-agent to get messages from. Default is None.
- 返回:
The messages from the memory including the sub-agent’s system prompt.
- 返回类型:
List[dict]
- class lagent.agents.agent.AsyncAgentMixin
- async forward(*message, session_id=0, **kwargs)
- 参数:
message (lagent.schema.AgentMessage) –
- 返回类型:
Union[lagent.schema.AgentMessage, str]
- class lagent.agents.agent.AsyncAgent(llm=None, template=None, memory=dict(type=Memory), output_format=None, aggregator=dict(type=DefaultAggregator), name=None, description=None, hooks=None)
Bases:
AsyncAgentMixin,AgentAsynchronous variant of the Agent class
- 参数:
llm (Union[lagent.llms.BaseLLM, Dict]) –
template (Union[lagent.prompts.prompt_template.PromptTemplate, str, dict, List[dict]]) –
memory (Dict) –
output_format (Optional[Dict]) –
aggregator (Dict) –
name (Optional[str]) –
description (Optional[str]) –
hooks (Optional[Union[List[Dict], Dict]]) –
- class lagent.agents.agent.StreamingAgentMixin
Component that makes agent calling output a streaming response.
- forward(*message, session_id=0, **kwargs)
- 参数:
message (lagent.schema.AgentMessage) –
- 返回类型:
Generator[Union[lagent.schema.AgentMessage, Tuple[lagent.schema.ModelStatusCode, str]], None, None]
- class lagent.agents.agent.AsyncStreamingAgentMixin
Component that makes asynchronous agent calling output a streaming response.
- async forward(*message, session_id=0, **kwargs)
- 参数:
message (lagent.schema.AgentMessage) –
- 返回类型:
AsyncGenerator[Union[lagent.schema.AgentMessage, Tuple[lagent.schema.ModelStatusCode, str]], None]
- class lagent.agents.agent.StreamingAgent(llm=None, template=None, memory=dict(type=Memory), output_format=None, aggregator=dict(type=DefaultAggregator), name=None, description=None, hooks=None)
Bases:
StreamingAgentMixin,AgentStreaming variant of the Agent class
- 参数:
llm (Union[lagent.llms.BaseLLM, Dict]) –
template (Union[lagent.prompts.prompt_template.PromptTemplate, str, dict, List[dict]]) –
memory (Dict) –
output_format (Optional[Dict]) –
aggregator (Dict) –
name (Optional[str]) –
description (Optional[str]) –
hooks (Optional[Union[List[Dict], Dict]]) –
- class lagent.agents.agent.AsyncStreamingAgent(llm=None, template=None, memory=dict(type=Memory), output_format=None, aggregator=dict(type=DefaultAggregator), name=None, description=None, hooks=None)
Bases:
AsyncStreamingAgentMixin,AgentStreaming variant of the AsyncAgent class
- 参数:
llm (Union[lagent.llms.BaseLLM, Dict]) –
template (Union[lagent.prompts.prompt_template.PromptTemplate, str, dict, List[dict]]) –
memory (Dict) –
output_format (Optional[Dict]) –
aggregator (Dict) –
name (Optional[str]) –
description (Optional[str]) –
hooks (Optional[Union[List[Dict], Dict]]) –
- class lagent.agents.agent.Sequential(*agents, **kwargs)
Bases:
AgentSequential is an agent container that forwards messages to each agent in the order they are added.
- 参数:
agents (Union[Agent, Iterable]) –
- forward(*message, session_id=0, exit_at=None, **kwargs)
- 参数:
message (lagent.schema.AgentMessage) –
exit_at (Optional[int]) –
- 返回类型:
- class lagent.agents.agent.AsyncSequential(*agents, **kwargs)
Bases:
AsyncAgentMixin,SequentialSequential is an agent container that forwards messages to each agent in the order they are added.
- 参数:
agents (Union[Agent, Iterable]) –
- async forward(*message, session_id=0, exit_at=None, **kwargs)
- 参数:
message (lagent.schema.AgentMessage) –
exit_at (Optional[int]) –
- 返回类型:
- class lagent.agents.agent.StreamingSequential(*agents, **kwargs)
Bases:
StreamingAgentMixin,SequentialStreaming variant of the Sequential class
- 参数:
agents (Union[Agent, Iterable]) –
- forward(*message, session_id=0, exit_at=None, **kwargs)
- 参数:
message (lagent.schema.AgentMessage) –
exit_at (Optional[int]) –
- class lagent.agents.agent.AsyncStreamingSequential(*agents, **kwargs)
Bases:
AsyncStreamingAgentMixin,SequentialStreaming variant of the AsyncSequential class
- 参数:
agents (Union[Agent, Iterable]) –
- async forward(*message, session_id=0, exit_at=None, **kwargs)
- 参数:
message (lagent.schema.AgentMessage) –
exit_at (Optional[int]) –
- class lagent.agents.agent.AgentContainerMixin
- class lagent.agents.agent.AgentList(agents=None)
Bases:
Agent,collections.UserList,AgentContainerMixinAgent is the basic unit of the system. It is responsible for communicating with the LLM, managing the memory, and handling the message aggregation and parsing. It can also be extended with hooks
- 参数:
llm (Union[BaseLLM, Dict]) – The language model used by the agent.
template (Union[PromptTemplate, str]) – The template used to format the messages.
memory (Dict) – The memory used by the agent.
output_format (Dict) – The output format used by the agent.
aggregator (Dict) – The aggregator used by the agent.
name (Optional[str]) – The name of the agent.
description (Optional[str]) – The description of the agent.
hooks (Optional[Union[List[Dict], Dict]]) – The hooks used by the agent.
agents (Optional[Iterable[Agent]]) –
- 返回:
The response message.
- 返回类型:
- name = None
- class lagent.agents.agent.AgentDict(agents=None)
Bases:
Agent,collections.UserDict,AgentContainerMixinAgent is the basic unit of the system. It is responsible for communicating with the LLM, managing the memory, and handling the message aggregation and parsing. It can also be extended with hooks
- 参数:
llm (Union[BaseLLM, Dict]) – The language model used by the agent.
template (Union[PromptTemplate, str]) – The template used to format the messages.
memory (Dict) – The memory used by the agent.
output_format (Dict) – The output format used by the agent.
aggregator (Dict) – The aggregator used by the agent.
name (Optional[str]) – The name of the agent.
description (Optional[str]) – The description of the agent.
hooks (Optional[Union[List[Dict], Dict]]) – The hooks used by the agent.
agents (Optional[Mapping[str, Agent]]) –
- 返回:
The response message.
- 返回类型:
- name = None