recipient_tool
langroid/agent/tools/recipient_tool.py
The recipient_tool
is used to send a message to a specific recipient.
Various methods from the RecipientTool and AddRecipientTool class
are inserted into the Agent as methods (see langroid/agent/base.py
,
the method _get_tool_list()
).
See usage examples in tests/main/test_multi_agent_complex.py
and
tests/main/test_recipient_tool.py
.
AddRecipientTool
¶
Bases: ToolMessage
Used by LLM to add a recipient to the previous message, when it has forgotten to specify a recipient. This avoids having to re-generate the previous message (and thus saves token-cost and time).
response(agent)
¶
Returns:
Type | Description |
---|---|
ChatDocument
|
with content set to self.content and metadata.recipient set to self.recipient. |
Source code in langroid/agent/tools/recipient_tool.py
RecipientTool
¶
Bases: ToolMessage
Used by LLM to send a message to a specific recipient.
Useful in cases where an LLM is talking to 2 or more agents (or an Agent and human user), and needs to specify which agent (task) its message is intended for. The recipient name should be the name of a task (which is normally the name of the agent that the task wraps, although the task can have its own name).
To use this tool/function-call, LLM must generate a JSON structure
with these fields:
{
"request": "recipient_message", # also the function name when using fn-calling
"intended_recipient": content
will be sent to the intended_recipient
task.
create(recipients, default='')
classmethod
¶
Create a restricted version of RecipientTool that only allows certain recipients, and possibly sets a default recipient.
Source code in langroid/agent/tools/recipient_tool.py
instructions()
classmethod
¶
Generate instructions for using this tool/function. These are intended to be appended to the system message of the LLM.
Source code in langroid/agent/tools/recipient_tool.py
response(agent)
¶
When LLM has correctly used this tool, construct a ChatDocument with an explicit recipient, and make it look like it is from the LLM.
Returns:
Type | Description |
---|---|
ChatDocument
|
with content set to self.content and metadata.recipient set to self.intended_recipient. |
Source code in langroid/agent/tools/recipient_tool.py
handle_message_fallback(agent, msg)
staticmethod
¶
Response of agent if this tool is not used, e.g.
the LLM simply sends a message without using this tool.
This method has two purposes:
(a) Alert the LLM that it has forgotten to specify a recipient, and prod it
to use the add_recipient
tool to specify just the recipient
(and not re-generate the entire message).
(b) Save the content of the message in the agent's content
field,
so the agent can construct a ChatDocument with this content once LLM
later specifies a recipient using the add_recipient
tool.
This method is used to set the agent's handle_message_fallback() method.
Returns:
Type | Description |
---|---|
str
|
reminder to LLM to use the |