Assistant subgraph tool
Tool to call an assistant as a subgraph of the main graph.
Probably also works within a subgraph (i.e. akin to recursive calling)
Thoughts:
- Any assistant that should be callable as a sub-graph needs to be marked as such
- Maybe this requires also adding some information like a description that can be used for the tool call
- Also determine what arguments should be used when calling the specific assistant
- E.g. message_to_assistant, pass_num_previous_messages
- Probably should choose these from a fixed list rather than trying to make dynamic
- Basically a single tool that works similarly for all assistants... I just need to control how the LLM
sees the assistant tool call options.
- The LLM should be able to see many instances of effectively the same tool, but with different descriptions and names depending on what sub-assistant it calls.
- Load information about available sub_assistants from the current assistant_schema when generating the tools to provide the LLM (append to the current tools provided)
SUB_ASSISTANT_PREFIX = 'sub_assistant__'
module-attribute
__all__ = ['SUB_ASSISTANT_PREFIX', 'AssistantSubgraphArgs', 'AssistantSubgraphArtifact', 'AssistantSubgraphCallTool', 'assistant_name_from_tool_name', 'tool_name_from_assistant', 'tool_name_from_assistant_name']
module-attribute
logger = logging.getLogger(__name__)
module-attribute
AssistantSubgraphArgs
Bases: BaseModel
Args common to all assistant subgraph calls.
The InjectedState comes from the additional sub_assistant_tool_input schema.
message_to_assistant = Field(description="Message to pass as latest message to the sub-assistant. E.g., instructions on what the sub-assistant should do, including relevant information (that isn't passed via previous messages/contexts)")
class-attribute
instance-attribute
parent_conv_messages
instance-attribute
parent_steps_remaining
instance-attribute
parent_summary_of_conversation
instance-attribute
pass_contexts = Field(default_factory=list, description='The call_ids of any contexts (i.e. tool responses) to pass on to the sub-assistant.')
class-attribute
instance-attribute
pass_num_previous_messages = Field(default=0, description='Number of previous messages from current conversation to pass to the sub-assistant.(This includes only user/assistant messages. Not tool_call/tool_response/system.)')
class-attribute
instance-attribute
resume_conversation_uid = Field(default=None, description="The uid of a sub-assistant to continue conversing with. (i.e. if sub-assistant was previously called, and current request is relevant to that previous call). 'None' will create a new conversation for the sub-assistant.")
class-attribute
instance-attribute
sub_assistant_states
instance-attribute
AssistantSubgraphArtifact
Bases: TypedDict
input
instance-attribute
response_messages
instance-attribute
returning_incomplete
instance-attribute
sub_assistant_state_data
instance-attribute
subgraph_uid
instance-attribute
AssistantSubgraphCallTool
Bases: BaseTool
args_schema = AssistantSubgraphArgs
class-attribute
instance-attribute
assistant_config_id
instance-attribute
description = Field(description='Sub-assistants tool description. (i.e. what does the sub-assistant do, and how should it be used, etc.)')
class-attribute
instance-attribute
name = Field(description='Name of assistant tool -- Must be set at tool creation to match the tool call.')
class-attribute
instance-attribute
read_only_uow
instance-attribute
response_format = 'content_and_artifact'
class-attribute
instance-attribute
tags = Field(default_factory=lambda: ['assistant_subgraph'])
class-attribute
instance-attribute
MissingConfigError
Bases: LanggraphError
MissingSubgraphDataError
Bases: LanggraphError
SubgraphInfo
dataclass
previous_messages
instance-attribute
subgraph_uid
instance-attribute
summary_of_conversation
instance-attribute
__init__(subgraph_uid, previous_messages, summary_of_conversation)
assistant_name_from_tool_name(tool_name)
generate_input_content(tool_input)
Generate the input content for the sub-assistant call.
Generate a single "user" message content to the sub_assistant from the parent assistant.
Form: - message from parent - previous messages from parent -- If passed - previous contexts from parent -- If passed