File tree Expand file tree Collapse file tree 4 files changed +77
-1
lines changed
template_langgraph/agents/task_decomposer_agent Expand file tree Collapse file tree 4 files changed +77
-1
lines changed Original file line number Diff line number Diff line change 55 "graphs" : {
66 "chat_with_tools_agent" : " template_langgraph.agents.chat_with_tools_agent.agent:graph" ,
77 "kabuto_helpdesk_agent" : " template_langgraph.agents.kabuto_helpdesk_agent:graph" ,
8- "issue_formatter_agent" : " template_langgraph.agents.issue_formatter_agent.agent:graph"
8+ "issue_formatter_agent" : " template_langgraph.agents.issue_formatter_agent.agent:graph" ,
9+ "task_decomposer_agent" : " template_langgraph.agents.task_decomposer_agent.agent:graph"
910 },
1011 "env" : " .env"
1112}
Original file line number Diff line number Diff line change 1+ from langgraph .graph import END , StateGraph
2+
3+ from template_langgraph .agents .chat_with_tools_agent .models import AgentState
4+ from template_langgraph .llms .azure_openais import AzureOpenAiWrapper
5+ from template_langgraph .loggers import get_logger
6+
7+ logger = get_logger (__name__ )
8+
9+
10+ class TaskDecomposerAgent :
11+ def __init__ (self ):
12+ self .llm = AzureOpenAiWrapper ().chat_model
13+
14+ def create_graph (self ):
15+ """Create the main graph for the agent."""
16+ # Create the workflow state graph
17+ workflow = StateGraph (AgentState )
18+
19+ # Create nodes
20+ workflow .add_node ("chat" , self .chat )
21+
22+ # Create edges
23+ workflow .set_entry_point ("chat" )
24+ workflow .add_edge ("chat" , END )
25+
26+ # Compile the graph
27+ return workflow .compile ()
28+
29+ def chat (self , state : AgentState ) -> AgentState :
30+ """Chat with tools using the state."""
31+ logger .info (f"Chatting with tools using state: { state } " )
32+ return {
33+ "messages" : [
34+ self .llm .invoke (state ["messages" ]),
35+ ]
36+ }
37+
38+ def draw_mermaid_png (self ) -> bytes :
39+ """Draw the graph in Mermaid format."""
40+ return self .create_graph ().get_graph ().draw_mermaid_png ()
41+
42+
43+ graph = TaskDecomposerAgent ().create_graph ()
Original file line number Diff line number Diff line change 1+ from collections .abc import Sequence
2+ from typing import (
3+ Annotated ,
4+ TypedDict ,
5+ )
6+
7+ from langchain_core .messages import (
8+ BaseMessage ,
9+ )
10+ from langgraph .graph .message import add_messages
11+ from pydantic import BaseModel , Field
12+
13+
14+ class Task (BaseModel ):
15+ title : str = Field (..., description = "Title of the task" )
16+ description : str = Field (..., description = "Description of the task" )
17+ priority : int = Field (..., description = "Priority of the task (1-5)" )
18+ due_date : str | None = Field (None , description = "Due date of the task (YYYY-MM-DD format)" )
19+ assigned_to : str | None = Field (None , description = "Name of the agent assigned to the task" )
20+
21+
22+ class AgentInput (BaseModel ):
23+ request : str = Field (..., description = "Request from the user" )
24+
25+
26+ class AgentOutput (BaseModel ):
27+ response : str = Field (..., description = "Response from the agent" )
28+
29+
30+ class AgentState (TypedDict ):
31+ messages : Annotated [Sequence [BaseMessage ], add_messages ]
32+ decomposed_tasks : Sequence [Task ]
You can’t perform that action at this time.
0 commit comments