Skip to content

Commit e99a88d

Browse files
authored
Merge pull request #237 from sicoyle/simplify-agent-creation-part-one
Simplify agent creation part one
2 parents 83f291e + 21cbe63 commit e99a88d

File tree

65 files changed

+1853
-1549
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1853
-1549
lines changed

dapr_agents/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from dapr_agents.agents.agent import Agent
22
from dapr_agents.agents.durableagent import DurableAgent
3+
from dapr_agents.agents.memory_store import MemoryStore
34
from dapr_agents.executors import DockerCodeExecutor, LocalCodeExecutor
45
from dapr_agents.llm.dapr import DaprChatClient
56
from dapr_agents.llm.elevenlabs import ElevenLabsSpeechClient
@@ -22,6 +23,7 @@
2223
__all__ = [
2324
"Agent",
2425
"DurableAgent",
26+
"MemoryStore",
2527
"DockerCodeExecutor",
2628
"LocalCodeExecutor",
2729
"ElevenLabsSpeechClient",

dapr_agents/agents/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .agent.agent import Agent
22
from .base import AgentBase
33
from .durableagent.agent import DurableAgent
4+
from .memory_store import MemoryStore
45

5-
__all__ = ["AgentBase", "Agent", "DurableAgent"]
6+
__all__ = ["AgentBase", "Agent", "DurableAgent", "MemoryStore"]

dapr_agents/agents/agent/agent.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ class Agent(AgentBase):
2121
It integrates tools and processes them based on user inputs and task orchestration.
2222
"""
2323

24+
def get_chat_history(self, task: Optional[str] = None) -> List[Dict[str, Any]]:
25+
"""
26+
Retrieves the chat history as a list of dictionaries.
27+
28+
Args:
29+
task (Optional[str]): The task or query provided by the user.
30+
31+
Returns:
32+
List[Dict[str, Any]]: The chat history as dictionaries.
33+
"""
34+
return self.memory_store.get_messages()
35+
2436
async def run(self, input_data: Optional[Union[str, Dict[str, Any]]] = None) -> Any:
2537
"""
2638
Runs the agent with the given input, supporting graceful shutdown.
@@ -69,15 +81,15 @@ async def _run_agent(
6981
) -> Any:
7082
"""
7183
Internal method for running the agent logic.
72-
Formats messages, updates memory, and drives the conversation loop.
84+
Formats messages, updates conversation history, and drives the conversation loop.
7385
7486
Args:
7587
input_data (Optional[Union[str, Dict[str, Any]]]): Input for the agent, can be a string or dict.
7688
Returns:
7789
Any: The result of the agent's conversation loop.
7890
"""
7991
logger.debug(
80-
f"Agent run started with input: {input_data if input_data else 'Using memory context'}"
92+
f"Agent run started with input: {input_data if input_data else 'Using session conversation context'}"
8193
)
8294

8395
# Construct messages using only input_data; chat history handled internally
@@ -91,7 +103,7 @@ async def _run_agent(
91103
if input_data and user_message_copy:
92104
# Add the new user message to memory only if input_data is provided and user message exists
93105
user_msg = UserMessage(content=user_message_copy.get("content", ""))
94-
self.memory.add_message(user_msg)
106+
self.memory_store.add_message(user_msg)
95107

96108
# Always print the last user message for context, even if no input_data is provided
97109
if user_message_copy is not None:
@@ -160,8 +172,8 @@ async def run_and_record(tool_call: ToolCall) -> ToolMessage:
160172
)
161173
# Print the tool message for visibility
162174
self.text_formatter.print_message(tool_message)
163-
# Add tool message to memory
164-
self.memory.add_message(tool_message)
175+
# Add tool message to storage
176+
self.memory_store.add_message(tool_message)
165177
# Append tool message to the persistent audit log
166178
tool_execution_record = ToolExecutionRecord(
167179
tool_call_id=tool_id,
@@ -215,7 +227,7 @@ async def conversation(self, messages: List[Dict[str, Any]]) -> Any:
215227
else:
216228
assistant = response_message
217229
self.text_formatter.print_message(assistant)
218-
self.memory.add_message(assistant)
230+
self.memory_store.add_message(assistant)
219231

220232
# Handle tool calls response
221233
if assistant is not None and assistant.has_tool_calls():

0 commit comments

Comments
 (0)