agentconnect.prompts package¶
Prompt templates and tools for the AgentConnect framework.
This module provides the core logic for agent workflows, including prompt templates, tools for agent collaboration, and workflow definitions. It serves as the “brain” of the AgentConnect framework, enabling agents to make decisions, collaborate with other agents, and process complex tasks.
Key components:
Tools: Utilities for agent search, collaboration, and task decomposition
Workflows: LangGraph-based workflows for different agent types
Templates: Prompt templates for various agent interactions
Chain Factory: Utilities for creating LangChain chains
- class AgentWorkflow(agent_id, llm, tools, prompt_templates, custom_tools=None)¶
Bases:
object
Base class for agent workflows.
This class provides the foundation for creating agent workflows using LangGraph. It handles the creation of the workflow graph, tools, and prompt templates.
- Parameters:
agent_id (str)
llm (BaseChatModel)
tools (PromptTools)
prompt_templates (PromptTemplates)
custom_tools (List[BaseTool] | None)
- agent_id¶
Unique identifier for the agent
- llm¶
Language model to use
- tools¶
Tools available to the agent
- prompt_templates¶
Prompt templates for the agent
- custom_tools¶
Optional list of custom LangChain tools
- workflow¶
The workflow graph
- mode¶
The agent’s operational mode
- build_workflow()¶
Build the workflow graph for the agent.
- Return type:
StateGraph
- Returns:
A StateGraph instance representing the agent’s workflow.
- compile()¶
Compile the workflow with memory persistence.
- Returns:
The compiled workflow with memory persistence
- class AIAgentWorkflow(agent_id, system_prompt_config, llm, tools, prompt_templates, custom_tools=None)¶
Bases:
AgentWorkflow
Workflow for AI agents with enhanced capabilities.
This workflow extends the base AgentWorkflow with AI-specific capabilities and system prompt configuration.
- Parameters:
agent_id (str)
system_prompt_config (SystemPromptConfig)
llm (BaseChatModel)
tools (PromptTools)
prompt_templates (PromptTemplates)
custom_tools (List[BaseTool] | None)
- system_prompt_config¶
Configuration for the system prompt
- create_workflow_for_agent(agent_type, system_config, llm, tools, prompt_templates, agent_id=None, custom_tools=None)¶
Factory function to create workflows based on agent type.
- Parameters:
agent_type (
str
) – Type of agent workflow to createsystem_config (
SystemPromptConfig
) – System prompt configurationllm (
BaseChatModel
) – Language model to usetools (
PromptTools
) – Tools available to the agentprompt_templates (
PromptTemplates
) – Prompt templates for the agentagent_id (
Optional
[str
]) – Optional agent ID for tool contextcustom_tools (
Optional
[List
[BaseTool
]]) – Optional list of custom LangChain tools
- Return type:
- Returns:
An AgentWorkflow instance
- Raises:
ValueError – If the agent type is unknown
- class PromptTemplates¶
Bases:
object
Class for creating and managing prompt templates.
This class provides methods for creating different types of prompts, including system prompts, collaboration prompts, and ReAct prompts.
- static add_scratchpad_to_prompt(prompt)¶
Add a scratchpad to a prompt template.
- Parameters:
prompt (
ChatPromptTemplate
) – The prompt template to add a scratchpad to- Return type:
ChatPromptTemplate
- Returns:
A ChatPromptTemplate with a scratchpad
- static create_ai_message_prompt(content)¶
Create an AI message prompt template.
- Parameters:
content (
str
) – Content of the AI message- Return type:
AIMessagePromptTemplate
- Returns:
An AIMessagePromptTemplate
- static create_chat_template(system_message=None, human_messages=None, ai_messages=None, include_history=True)¶
Create a chat template from system, human, and AI messages.
- Parameters:
system_message (
Optional
[SystemMessagePromptTemplate
]) – Optional system messagehuman_messages (
Optional
[List
[HumanMessagePromptTemplate
]]) – Optional list of human messagesai_messages (
Optional
[List
[AIMessagePromptTemplate
]]) – Optional list of AI messagesinclude_history (
bool
) – Whether to include message history
- Return type:
ChatPromptTemplate
- Returns:
A ChatPromptTemplate
- static create_human_message_prompt(content)¶
Create a human message prompt template.
- Parameters:
content (
str
) – Content of the human message- Return type:
HumanMessagePromptTemplate
- Returns:
A HumanMessagePromptTemplate
- classmethod create_prompt(prompt_type, config=None, include_history=True, system_prompt=None, tools=None)¶
Create a prompt template based on the prompt type and configuration.
- Parameters:
- Return type:
ChatPromptTemplate
- Returns:
A ChatPromptTemplate
- Raises:
ValueError – If the prompt type is not supported or the configuration is invalid
- static get_capability_matching_prompt(config)¶
Get a capability matching prompt template based on the provided configuration.
- Parameters:
config (
CapabilityMatchingConfig
) – Configuration for the capability matching prompt- Return type:
SystemMessagePromptTemplate
- Returns:
A SystemMessagePromptTemplate
- static get_collaboration_prompt(config)¶
Get a collaboration prompt template based on the provided configuration.
- Parameters:
config (
CollaborationConfig
) – Configuration for the collaboration prompt- Return type:
SystemMessagePromptTemplate
- Returns:
A SystemMessagePromptTemplate
- static get_react_prompt(config)¶
Get a ReAct prompt template based on the provided configuration.
- Parameters:
config (
ReactConfig
) – Configuration for the ReAct prompt- Return type:
SystemMessagePromptTemplate
- Returns:
A SystemMessagePromptTemplate
- static get_supervisor_prompt(config)¶
Get a supervisor prompt template based on the provided configuration.
- Parameters:
config (
SupervisorConfig
) – Configuration for the supervisor prompt- Return type:
SystemMessagePromptTemplate
- Returns:
A SystemMessagePromptTemplate
- static get_system_prompt(config)¶
Get a system prompt template based on the provided configuration.
- Parameters:
config (
SystemPromptConfig
) – Configuration for the system prompt- Return type:
SystemMessagePromptTemplate
- Returns:
A SystemMessagePromptTemplate
- static get_task_decomposition_prompt(config)¶
Get a task decomposition prompt template based on the provided configuration.
- Parameters:
config (
TaskDecompositionConfig
) – Configuration for the task decomposition prompt- Return type:
SystemMessagePromptTemplate
- Returns:
A SystemMessagePromptTemplate
- class PromptTools(agent_registry, communication_hub, llm=None)¶
Bases:
object
Class for creating and managing tools for agent prompts.
This class is responsible for creating, registering, and managing the tools that agents can use to perform actions such as searching for other agents, sending collaboration requests, and decomposing tasks.
Each agent has its own isolated set of tools through a dedicated ToolRegistry instance, ensuring that tools are properly configured for the specific agent using them.
- Parameters:
agent_registry (AgentRegistry)
communication_hub (CommunicationHub)
- agent_registry¶
Registry for accessing agent information
- communication_hub¶
Hub for agent communication
- llm¶
Optional language model for tools that require LLM capabilities
- _current_agent_id¶
ID of the agent currently using these tools
- _tool_registry¶
Registry for managing available tools
- _available_capabilities¶
Cached list of available capabilities
- _agent_specific_tools_registered¶
Flag indicating if agent-specific tools are registered
- create_agent_search_tool()¶
Create a tool for searching agents by capability.
- Return type:
StructuredTool
- create_send_collaboration_request_tool()¶
Create a tool for sending collaboration requests to other agents.
- Return type:
StructuredTool
- create_task_decomposition_tool()¶
Create a tool for decomposing complex tasks into subtasks.
This tool helps agents break down complex tasks into smaller, more manageable subtasks. It’s useful for organizing and prioritizing work, especially for multi-step processes that would be difficult to tackle as a single unit.
The tool uses the LLM to analyze the task and create a structured decomposition with clear, actionable subtasks. Each subtask includes a unique ID, title, and description.
- Return type:
StructuredTool
- Returns:
A StructuredTool for task decomposition that can be used in agent workflows
Note
If the LLM is not available, the tool will fall back to a simple rule-based decomposition.
- create_tool_from_function(func, name, description, args_schema, category=None, coroutine=None)¶
Create a tool from a function with proper async support.
This method creates a LangChain StructuredTool that can be used in agent workflows. It supports both synchronous and asynchronous implementations of the tool, allowing for efficient handling of I/O-bound operations.
The tool is automatically registered in the tool registry with the specified category, making it available for agent use.
- Parameters:
func (
Callable
[...
,Any
]) – The synchronous function implementationname (
str
) – Name of the tool (must be unique)description (
str
) – Description of the tool that will be shown to the agentargs_schema (
Type
[TypeVar
(T
, bound=BaseModel
)]) – Pydantic model for the tool’s arguments validationcategory (
Optional
[str
]) – Optional category for the tool (e.g., ‘collaboration’, ‘task_management’)coroutine (
Optional
[Callable
[...
,Awaitable
[Any
]]]) – Optional async implementation of the function for better performance
- Return type:
StructuredTool
- Returns:
A StructuredTool that can be used in LangChain workflows
Note
If both sync and async implementations are provided, the async version will be used when the agent is running in an async context.
- get_tools_for_workflow(categories=None, agent_id=None)¶
Get tools for a specific workflow based on categories.
This method retrieves the appropriate tools for a workflow, optionally filtered by category. It’s used by agent workflows to get the tools they need for specific tasks.
- Parameters:
- Return type:
List
[StructuredTool
]- Returns:
List of StructuredTool instances configured for the agent
Note
If categories is None, all tools in the registry will be returned. The agent_id parameter is used only for logging and doesn’t change the current agent context.
- set_current_agent(agent_id)¶
Set the current agent ID for context in tools.
This method establishes the context for which agent is using the tools, which is essential for agent-specific tools like collaboration requests. It also triggers the registration of agent-specific tools if they haven’t been registered yet.
Note
This method logs whenever the agent context changes to help with debugging and tracing agent interactions.
- create_agent_workflow(agent_type, system_config, llm, agent_registry=None, tools=None, prompt_templates=None, agent_id=None, custom_tools=None)¶
Create a workflow for an agent.
- Parameters:
agent_type (
str
) – Type of agent workflow to createsystem_config (
SystemPromptConfig
) – Configuration for the system promptllm (
BaseChatModel
) – Language model to use for the agentagent_registry (
Optional
[AgentRegistry
]) – Registry of agents for collaborationtools (
Optional
[List
[BaseTool
]]) – Tools for the agent to useprompt_templates (
Optional
[PromptTemplates
]) – Templates for promptscustom_tools (
Optional
[List
[BaseTool
]]) – Custom tools for the agent
- Return type:
- Returns:
An agent workflow that can be compiled and run
Submodules¶
- agentconnect.prompts.agent_prompts module
AgentMode
WorkflowState
WorkflowState.THINKING
WorkflowState.RESPONDING
WorkflowState.TOOL_CALLING
WorkflowState.COLLABORATION
WorkflowState.TASK_DECOMPOSITION
WorkflowState.CAPABILITY_MATCHING
WorkflowState.ERROR
WorkflowState.COMPLETE
WorkflowState.THINKING
WorkflowState.RESPONDING
WorkflowState.TOOL_CALLING
WorkflowState.COLLABORATION
WorkflowState.TASK_DECOMPOSITION
WorkflowState.CAPABILITY_MATCHING
WorkflowState.ERROR
WorkflowState.COMPLETE
AgentState
AgentState.messages
AgentState.sender
AgentState.receiver
AgentState.mode
AgentState.capabilities
AgentState.runnable_result
AgentState.collaboration_results
AgentState.agents_found
AgentState.retry_count
AgentState.error
AgentState.context_reset
AgentState.topic_changed
AgentState.last_interaction_time
AgentState.messages
AgentState.sender
AgentState.receiver
AgentState.mode
AgentState.capabilities
AgentState.runnable_result
AgentState.collaboration_results
AgentState.agents_found
AgentState.retry_count
AgentState.error
AgentState.context_reset
AgentState.topic_changed
AgentState.last_interaction_time
CollaborationState
CollaborationState.found_agents
CollaborationState.capabilities
CollaborationState.collaboration_result
CollaborationState.subtasks
CollaborationState.current_subtask
CollaborationState.completed_subtasks
CollaborationState.task_description
CollaborationState.action
CollaborationState.error
CollaborationState.found_agents
CollaborationState.capabilities
CollaborationState.collaboration_result
CollaborationState.subtasks
CollaborationState.current_subtask
CollaborationState.completed_subtasks
CollaborationState.task_description
CollaborationState.action
CollaborationState.error
CollaborationState.messages
CollaborationState.sender
CollaborationState.receiver
CollaborationState.mode
CollaborationState.runnable_result
CollaborationState.collaboration_results
CollaborationState.agents_found
CollaborationState.retry_count
CollaborationState.context_reset
CollaborationState.topic_changed
CollaborationState.last_interaction_time
DecisionOutput
TaskDecompositionOutput
AgentWorkflow
AIAgentWorkflow
TaskDecompositionWorkflow
CollaborationRequestWorkflow
create_workflow_for_agent()
- agentconnect.prompts.chain_factory module
- agentconnect.prompts.tools module
Subtask
TaskDecompositionResult
AgentSearchInput
AgentSearchOutput
SendCollaborationRequestInput
SendCollaborationRequestOutput
TaskDecompositionInput
TaskDecompositionOutput
ToolRegistry
PromptTools
PromptTools.agent_registry
PromptTools.communication_hub
PromptTools.llm
PromptTools._current_agent_id
PromptTools._tool_registry
PromptTools._available_capabilities
PromptTools._agent_specific_tools_registered
PromptTools.create_tool_from_function()
PromptTools.create_agent_search_tool()
PromptTools.create_send_collaboration_request_tool()
PromptTools.create_task_decomposition_tool()
PromptTools.set_current_agent()
PromptTools.get_tools_for_workflow()