Module: Multistep Agent
- class diskurs.multistep_agent.MultiStepAgent
Bases:
BaseAgent[MultistepPrompt]- __init__(name, prompt, llm_client, topics=None, dispatcher=None, tool_executor=None, tools=None, max_reasoning_steps=5, max_trials=5, init_prompt_arguments_with_longterm_memory=True)
- Parameters:
name (str)
prompt (MultistepPrompt)
llm_client (LLMClient)
topics (list[str] | None)
dispatcher (ConversationDispatcher | None)
tool_executor (ToolExecutor | None)
tools (list[ToolDescription] | None)
max_reasoning_steps (int)
max_trials (int)
init_prompt_arguments_with_longterm_memory (bool)
- async compute_tool_response(response)
Executes the tool calls in the response and returns the tool responses.
- Parameters:
response (Conversation) – The conversation object containing the tool calls to execute.
- Returns:
One or more ChatMessage objects containing the tool responses.
- Return type:
list[ChatMessage]
- classmethod create(name, prompt, llm_client, **kwargs)
- Parameters:
name (str)
prompt (MultistepPrompt)
llm_client (LLMClient)
- Return type:
Self
- async generate_validated_response(conversation, message_type=MessageType.CONVERSATION)
Generates a validated response for the given conversation.
This method attempts to generate a valid response for the conversation by interacting with the LLM client and validating the response. It performs multiple trials if necessary, and handles tool calls and corrective messages.
- Parameters:
conversation (Conversation) – The conversation object to generate a response for.
message_type (MessageType) – The type of message to render the user prompt as, defaults to MessageType.CONVERSATION.
- Returns:
The updated conversation object with the validated response.
- Return type:
- async handle_tool_call(conversation, response)
This method handles a tool call by executing the tool and updating the conversation with the tool response.
- Parameters:
conversation – The conversation object to add the result to.
response – The response object containing the tool call to handle.
- Returns:
The updated conversation object with the tool response.
- async invoke(conversation, message_type=MessageType.CONVERSATION, reset_prompt=True)
Executes the reasoning steps to process the conversation.
- Parameters:
conversation (Conversation) – The conversation object to process
message_type – The type of message to use
reset_prompt – Whether to reset the prompt with fresh prompts and prompt arguments before invoking
- Returns:
The updated conversation after processing
- Return type:
- name: str
- async process_conversation(conversation)
Receives a conversation from the dispatcher, i.e. message bus, processes it and finally publishes a deep copy of the resulting conversation back to the dispatcher.
- Parameters:
conversation (Conversation) – The conversation object to process.
- Return type:
None
- register_dispatcher(dispatcher)
Register a dispatcher with the agent.
- Parameters:
dispatcher (ConversationDispatcher) – The dispatcher to register
- Return type:
None
- register_tools(tools)
Register tools with the agent.
- Parameters:
tools (list[Callable] | Callable) – A list of callables or a single callable to register as tools
- Return type:
None
- return_fail_validation_message(response)
Returns a fail validation message when max trials are exhausted.
- Parameters:
response – The conversation to add the fail message to
- Returns:
The updated conversation with the fail message
- property topics: list[str]
- class diskurs.multistep_agent.MultistepAgentFinalizer
Bases:
MultiStepAgent,FinalizerMixin- __init__(**kwargs)
- async compute_tool_response(response)
Executes the tool calls in the response and returns the tool responses.
- Parameters:
response (Conversation) – The conversation object containing the tool calls to execute.
- Returns:
One or more ChatMessage objects containing the tool responses.
- Return type:
list[ChatMessage]
- classmethod create(name, prompt, llm_client, **kwargs)
- Parameters:
name (str)
prompt (MultistepPrompt)
llm_client (LLMClient)
- Return type:
Self
- final_properties: list[str]
- async finalize_conversation(conversation)
Finalize the conversation by invoking the agent and extracting final properties.
- Parameters:
conversation (Conversation) – The conversation to finalize
- Return type:
None
- async generate_validated_response(conversation, message_type=MessageType.CONVERSATION)
Generates a validated response for the given conversation.
This method attempts to generate a valid response for the conversation by interacting with the LLM client and validating the response. It performs multiple trials if necessary, and handles tool calls and corrective messages.
- Parameters:
conversation (Conversation) – The conversation object to generate a response for.
message_type (MessageType) – The type of message to render the user prompt as, defaults to MessageType.CONVERSATION.
- Returns:
The updated conversation object with the validated response.
- Return type:
- async handle_tool_call(conversation, response)
This method handles a tool call by executing the tool and updating the conversation with the tool response.
- Parameters:
conversation – The conversation object to add the result to.
response – The response object containing the tool call to handle.
- Returns:
The updated conversation object with the tool response.
- async invoke(conversation, message_type=MessageType.CONVERSATION, reset_prompt=True)
Executes the reasoning steps to process the conversation.
- Parameters:
conversation (Conversation) – The conversation object to process
message_type – The type of message to use
reset_prompt – Whether to reset the prompt with fresh prompts and prompt arguments before invoking
- Returns:
The updated conversation after processing
- Return type:
- name: str
- async process_conversation(conversation)
Receives a conversation from the dispatcher, i.e. message bus, processes it and finally publishes a deep copy of the resulting conversation back to the dispatcher.
- Parameters:
conversation (Conversation) – The conversation object to process.
- Return type:
None
- register_dispatcher(dispatcher)
Register a dispatcher with the agent.
- Parameters:
dispatcher (ConversationDispatcher) – The dispatcher to register
- Return type:
None
- register_tools(tools)
Register tools with the agent.
- Parameters:
tools (list[Callable] | Callable) – A list of callables or a single callable to register as tools
- Return type:
None
- return_fail_validation_message(response)
Returns a fail validation message when max trials are exhausted.
- Parameters:
response – The conversation to add the fail message to
- Returns:
The updated conversation with the fail message
- property topics: list[str]
- class diskurs.multistep_agent.MultistepAgentPredicate
Bases:
MultiStepAgent,ConversationResponder- __init__(name, prompt, llm_client, topics=None, dispatcher=None, tool_executor=None, tools=None, max_reasoning_steps=5, max_trials=5, init_prompt_arguments_with_longterm_memory=True)
- Parameters:
name (str)
prompt (MultistepPrompt)
llm_client (LLMClient)
topics (list[str] | None)
dispatcher (ConversationDispatcher | None)
tool_executor (ToolExecutor | None)
tools (list[ToolDescription] | None)
max_reasoning_steps (int)
max_trials (int)
init_prompt_arguments_with_longterm_memory (bool)
- async compute_tool_response(response)
Executes the tool calls in the response and returns the tool responses.
- Parameters:
response (Conversation) – The conversation object containing the tool calls to execute.
- Returns:
One or more ChatMessage objects containing the tool responses.
- Return type:
list[ChatMessage]
- classmethod create(name, prompt, llm_client, **kwargs)
- Parameters:
name (str)
prompt (MultistepPrompt)
llm_client (LLMClient)
- Return type:
Self
- async generate_validated_response(conversation, message_type=MessageType.CONVERSATION)
Generates a validated response for the given conversation.
This method attempts to generate a valid response for the conversation by interacting with the LLM client and validating the response. It performs multiple trials if necessary, and handles tool calls and corrective messages.
- Parameters:
conversation (Conversation) – The conversation object to generate a response for.
message_type (MessageType) – The type of message to render the user prompt as, defaults to MessageType.CONVERSATION.
- Returns:
The updated conversation object with the validated response.
- Return type:
- async handle_tool_call(conversation, response)
This method handles a tool call by executing the tool and updating the conversation with the tool response.
- Parameters:
conversation – The conversation object to add the result to.
response – The response object containing the tool call to handle.
- Returns:
The updated conversation object with the tool response.
- async invoke(conversation, message_type=MessageType.CONVERSATION, reset_prompt=True)
Executes the reasoning steps to process the conversation.
- Parameters:
conversation (Conversation) – The conversation object to process
message_type – The type of message to use
reset_prompt – Whether to reset the prompt with fresh prompts and prompt arguments before invoking
- Returns:
The updated conversation after processing
- Return type:
- name: str
- async process_conversation(conversation)
Receives a conversation from the dispatcher, i.e. message bus, processes it and finally publishes a deep copy of the resulting conversation back to the dispatcher.
- Parameters:
conversation (Conversation) – The conversation object to process.
- Return type:
None
- register_dispatcher(dispatcher)
Register a dispatcher with the agent.
- Parameters:
dispatcher (ConversationDispatcher) – The dispatcher to register
- Return type:
None
- register_tools(tools)
Register tools with the agent.
- Parameters:
tools (list[Callable] | Callable) – A list of callables or a single callable to register as tools
- Return type:
None
- async respond(conversation)
Responds to a conversation request.
This method processes the given conversation and generates a direct response. It’s designed for scenarios where a synchronous response is needed, such as when one agent needs information from another agent to proceed with processing.
- Parameters:
conversation (Conversation) – The conversation to process and respond to.
- Returns:
The updated conversation with the response included.
- Return type:
- return_fail_validation_message(response)
Returns a fail validation message when max trials are exhausted.
- Parameters:
response – The conversation to add the fail message to
- Returns:
The updated conversation with the fail message
- property topics: list[str]
- class diskurs.multistep_agent.ParallelMulstistepAgent
Bases:
MultiStepAgent- __init__(**kwargs)
Parallelize work, by first invoking the main conversation and then branching out the conversation to multiple :param invoke_on_final: whether we want to call the LLM again on the final result after applying the join function
- async branch_conversations(conversation)
- Parameters:
conversation (Conversation)
- Return type:
list[Conversation]
- async compute_tool_response(response)
Executes the tool calls in the response and returns the tool responses.
- Parameters:
response (Conversation) – The conversation object containing the tool calls to execute.
- Returns:
One or more ChatMessage objects containing the tool responses.
- Return type:
list[ChatMessage]
- classmethod create(name, prompt, llm_client, **kwargs)
- Parameters:
name (str)
prompt (MultistepPrompt)
llm_client (LLMClient)
- Return type:
Self
- async generate_validated_response(conversation, message_type=MessageType.CONVERSATION)
Generates a validated response for the given conversation.
This method attempts to generate a valid response for the conversation by interacting with the LLM client and validating the response. It performs multiple trials if necessary, and handles tool calls and corrective messages.
- Parameters:
conversation (Conversation) – The conversation object to generate a response for.
message_type (MessageType) – The type of message to render the user prompt as, defaults to MessageType.CONVERSATION.
- Returns:
The updated conversation object with the validated response.
- Return type:
- async handle_tool_call(conversation, response)
This method handles a tool call by executing the tool and updating the conversation with the tool response.
- Parameters:
conversation – The conversation object to add the result to.
response – The response object containing the tool call to handle.
- Returns:
The updated conversation object with the tool response.
- async invoke(conversation, message_type=MessageType.CONVERSATION, reset_prompt=True)
Executes the reasoning steps to process the conversation.
- Parameters:
conversation (Conversation) – The conversation object to process
message_type – The type of message to use
reset_prompt – Whether to reset the prompt with fresh prompts and prompt arguments before invoking
- Returns:
The updated conversation after processing
- Return type:
- async invoke_parallel(conversation, message_type=MessageType.CONVERSATION)
Parallelize work, by first invoking the main conversation and then branching out the conversation to multiple invoke calls. The first invoke is meant to identify parallelizable work, we then call branch_conversations to split the work into multiple conversations and then invoke each conversation in parallel.
- Parameters:
conversation (Conversation) – The conversation object to process.
message_type – The message type to use when generating responses.
- Returns:
The conversation object with the final result.
- Return type:
- async join_conversations(conversations)
- Parameters:
conversations (list[Conversation])
- Return type:
- name: str
- async process_conversation(conversation)
Receives a conversation from the dispatcher, i.e. message bus, processes it and finally publishes a deep copy of the resulting conversation back to the dispatcher.
- Parameters:
conversation (Conversation) – The conversation object to process.
- Return type:
None
- register_dispatcher(dispatcher)
Register a dispatcher with the agent.
- Parameters:
dispatcher (ConversationDispatcher) – The dispatcher to register
- Return type:
None
- register_tools(tools)
Register tools with the agent.
- Parameters:
tools (list[Callable] | Callable) – A list of callables or a single callable to register as tools
- Return type:
None
- return_fail_validation_message(response)
Returns a fail validation message when max trials are exhausted.
- Parameters:
response – The conversation to add the fail message to
- Returns:
The updated conversation with the fail message
- property topics: list[str]