dao-ai 0.0.25__py3-none-any.whl → 0.0.27__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
dao_ai/nodes.py CHANGED
@@ -19,9 +19,9 @@ from loguru import logger
19
19
  from dao_ai.config import (
20
20
  AgentModel,
21
21
  AppConfig,
22
- AppModel,
23
22
  ChatHistoryModel,
24
23
  FunctionHook,
24
+ MemoryModel,
25
25
  ToolModel,
26
26
  )
27
27
  from dao_ai.guardrails import reflection_guardrail, with_guardrails
@@ -31,12 +31,18 @@ from dao_ai.state import Context, IncomingState, SharedState
31
31
  from dao_ai.tools import create_tools
32
32
 
33
33
 
34
- def summarization_node(app_model: AppModel) -> RunnableLike:
35
- chat_history: ChatHistoryModel | None = app_model.chat_history
34
+ def summarization_node(chat_history: ChatHistoryModel) -> RunnableLike:
35
+ """
36
+ Create a summarization node for managing chat history.
37
+
38
+ Args:
39
+ chat_history: ChatHistoryModel configuration for summarization
40
+
41
+ Returns:
42
+ RunnableLike: A summarization node that processes messages
43
+ """
36
44
  if chat_history is None:
37
- raise ValueError(
38
- "AppModel must have chat_history configured to use summarization"
39
- )
45
+ raise ValueError("chat_history must be provided to use summarization")
40
46
 
41
47
  max_tokens: int = chat_history.max_tokens
42
48
  max_tokens_before_summary: int | None = chat_history.max_tokens_before_summary
@@ -93,23 +99,26 @@ def call_agent_with_summarized_messages(agent: CompiledStateGraph) -> RunnableLi
93
99
 
94
100
 
95
101
  def create_agent_node(
96
- app: AppModel,
97
102
  agent: AgentModel,
103
+ memory: Optional[MemoryModel] = None,
104
+ chat_history: Optional[ChatHistoryModel] = None,
98
105
  additional_tools: Optional[Sequence[BaseTool]] = None,
99
106
  ) -> RunnableLike:
100
107
  """
101
108
  Factory function that creates a LangGraph node for a specialized agent.
102
109
 
103
- This creates a node function that handles user requests using a specialized agent
104
- based on the provided agent_type. The function configures the agent with the
105
- appropriate model, prompt, tools, and guardrails from the model_config.
110
+ This creates a node function that handles user requests using a specialized agent.
111
+ The function configures the agent with the appropriate model, prompt, tools, and guardrails.
112
+ If chat_history is provided, it creates a workflow with summarization node.
106
113
 
107
114
  Args:
108
- model_config: Configuration containing models, prompts, tools, and guardrails
109
- agent_type: Type of agent to create (e.g., "general", "product", "inventory")
115
+ agent: AgentModel configuration for the agent
116
+ memory: Optional MemoryModel for memory store configuration
117
+ chat_history: Optional ChatHistoryModel for chat history summarization
118
+ additional_tools: Optional sequence of additional tools to add to the agent
110
119
 
111
120
  Returns:
112
- An agent callable function that processes state and returns responses
121
+ RunnableLike: An agent node that processes state and returns responses
113
122
  """
114
123
  logger.debug(f"Creating agent node for {agent.name}")
115
124
 
@@ -124,10 +133,10 @@ def create_agent_node(
124
133
  additional_tools = []
125
134
  tools: Sequence[BaseTool] = create_tools(tool_models) + additional_tools
126
135
 
127
- if app.orchestration.memory and app.orchestration.memory.store:
136
+ if memory and memory.store:
128
137
  namespace: tuple[str, ...] = ("memory",)
129
- if app.orchestration.memory.store.namespace:
130
- namespace = namespace + (app.orchestration.memory.store.namespace,)
138
+ if memory.store.namespace:
139
+ namespace = namespace + (memory.store.namespace,)
131
140
  logger.debug(f"Memory store namespace: {namespace}")
132
141
 
133
142
  tools += [
@@ -145,13 +154,15 @@ def create_agent_node(
145
154
  )
146
155
  logger.debug(f"post_agent_hook: {post_agent_hook}")
147
156
 
157
+ checkpointer: bool = memory and memory.checkpointer is not None
158
+
148
159
  compiled_agent: CompiledStateGraph = create_react_agent(
149
160
  name=agent.name,
150
161
  model=llm,
151
162
  prompt=make_prompt(agent.prompt),
152
163
  tools=tools,
153
164
  store=True,
154
- checkpointer=True,
165
+ checkpointer=checkpointer,
155
166
  state_schema=SharedState,
156
167
  context_schema=Context,
157
168
  pre_model_hook=pre_agent_hook,
@@ -166,8 +177,6 @@ def create_agent_node(
166
177
 
167
178
  agent_node: CompiledStateGraph
168
179
 
169
- chat_history: ChatHistoryModel = app.chat_history
170
-
171
180
  if chat_history is None:
172
181
  logger.debug("No chat history configured, using compiled agent directly")
173
182
  agent_node = compiled_agent
@@ -179,7 +188,7 @@ def create_agent_node(
179
188
  input=SharedState,
180
189
  output=SharedState,
181
190
  )
182
- workflow.add_node("summarization", summarization_node(app))
191
+ workflow.add_node("summarization", summarization_node(chat_history))
183
192
  workflow.add_node(
184
193
  "agent",
185
194
  call_agent_with_summarized_messages(agent=compiled_agent),