Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions atomic_agents/agents/base_chat_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pydantic import BaseModel, Field
from rich.json import JSON

from atomic_agents.lib.components.chat_memory import ChatMemory
from atomic_agents.lib.components.agent_memory import AgentMemory
from atomic_agents.lib.components.system_prompt_generator import SystemPromptContextProviderBase, SystemPromptGenerator


Expand Down Expand Up @@ -57,7 +57,7 @@ class Config:
class BaseChatAgentConfig(BaseModel):
client: instructor.client.Instructor = Field(..., description="Client for interacting with the language model.")
model: str = Field("gpt-3.5-turbo", description="The model to use for generating responses.")
memory: Optional[ChatMemory] = Field(None, description="Memory component for storing chat history.")
memory: Optional[AgentMemory] = Field(None, description="Memory component for storing chat history.")
system_prompt_generator: Optional[SystemPromptGenerator] = Field(
None, description="Component for generating system prompts."
)
Expand All @@ -80,9 +80,9 @@ class BaseChatAgent:
output_schema (Type[BaseAgentIO]): Schema for the output data.
client: Client for interacting with the language model.
model (str): The model to use for generating responses.
memory (ChatMemory): Memory component for storing chat history.
memory (AgentMemory): Memory component for storing chat history.
system_prompt_generator (SystemPromptGenerator): Component for generating system prompts.
initial_memory (ChatMemory): Initial state of the memory.
initial_memory (AgentMemory): Initial state of the memory.
"""

input_schema = BaseChatAgentInputSchema
Expand All @@ -99,7 +99,7 @@ def __init__(self, config: BaseChatAgentConfig):
self.output_schema = config.output_schema or self.output_schema
self.client = config.client
self.model = config.model
self.memory = config.memory or ChatMemory()
self.memory = config.memory or AgentMemory()
self.system_prompt_generator = config.system_prompt_generator or SystemPromptGenerator()
self.initial_memory = self.memory.copy()
self.current_user_input = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Message(BaseModel):
tool_call_id: Optional[str] = None


class ChatMemory:
class AgentMemory:
"""
Manages the chat history for an AI agent.

Expand All @@ -31,7 +31,7 @@ class ChatMemory:

def __init__(self, max_messages: Optional[int] = None):
"""
Initializes the ChatMemory with an empty history and optional constraints.
Initializes the AgentMemory with an empty history and optional constraints.

Args:
max_messages (Optional[int]): Maximum number of turns to keep in history.
Expand Down Expand Up @@ -116,14 +116,14 @@ def load(self, dict_list: List[Dict]) -> None:
# Optionally, manage overflow after loading all messages
self._manage_overflow()

def copy(self) -> "ChatMemory":
def copy(self) -> "AgentMemory":
"""
Creates a copy of the chat memory.

Returns:
ChatMemory: A copy of the chat memory.
AgentMemory: A copy of the chat memory.
"""
new_memory = ChatMemory(max_messages=self.max_messages)
new_memory = AgentMemory(max_messages=self.max_messages)
new_memory.load(self.dump())

return new_memory
Expand Down
2 changes: 1 addition & 1 deletion docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A full list of `Atomic_agents` project modules.
- [ToolInterfaceAgent](atomic_agents/agents/tool_interface_agent.md#toolinterfaceagent)
- [Lib](atomic_agents/lib/index.md#lib)
- [Components](atomic_agents/lib/components/index.md#components)
- [ChatMemory](atomic_agents/lib/components/chat_memory.md#chatmemory)
- [AgentMemory](atomic_agents/lib/components/agent_memory.md#AgentMemory)
- [SystemPromptGenerator](atomic_agents/lib/components/system_prompt_generator.md#systempromptgenerator)
- [Models](atomic_agents/lib/models/index.md#models)
- [WebDocument](atomic_agents/lib/models/web_document.md#webdocument)
Expand Down
4 changes: 2 additions & 2 deletions docs/api/atomic_agents/agents/base_chat_agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ generating system prompts, and obtaining responses from a language model.
- `output_schema` *Type[BaseAgentIO]* - Schema for the output data.
- `client` - Client for interacting with the language model.
- `model` *str* - The model to use for generating responses.
- `memory` *ChatMemory* - Memory component for storing chat history.
- `memory` *AgentMemory* - Memory component for storing chat history.
- `system_prompt_generator` *SystemPromptGenerator* - Component for generating system prompts.
- `initial_memory` *ChatMemory* - Initial state of the memory.
- `initial_memory` *AgentMemory* - Initial state of the memory.

#### Signature

Expand Down
70 changes: 35 additions & 35 deletions docs/api/atomic_agents/lib/components/chat_memory.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# ChatMemory
# AgentMemory

[Atomic_agents Index](../../../README.md#atomic_agents-index) / [Atomic Agents](../../index.md#atomic-agents) / [Lib](../index.md#lib) / [Components](./index.md#components) / ChatMemory
[Atomic_agents Index](../../../README.md#atomic_agents-index) / [Atomic Agents](../../index.md#atomic-agents) / [Lib](../index.md#lib) / [Components](./index.md#components) / AgentMemory

> Auto-generated documentation for [atomic_agents.lib.components.chat_memory](../../../../../atomic_agents/lib/components/chat_memory.py) module.
> Auto-generated documentation for [atomic_agents.lib.components.agent_memory](../../../../../atomic_agents/lib/components/agent_memory.py) module.

#### Attributes

- `memory` - Create a ChatMemory with a maximum of 5 messages: ChatMemory(max_messages=5)
- `memory` - Create a AgentMemory with a maximum of 5 messages: AgentMemory(max_messages=5)

- `content` - Test Case 1: Text()

Expand All @@ -25,21 +25,21 @@
- `content` - Test Case 8: Text()


- [ChatMemory](#chatmemory)
- [ChatMemory](#chatmemory-1)
- [ChatMemory()._manage_overflow](#chatmemory()_manage_overflow)
- [ChatMemory().add_message](#chatmemory()add_message)
- [ChatMemory().copy](#chatmemory()copy)
- [ChatMemory().dump](#chatmemory()dump)
- [ChatMemory().get_history](#chatmemory()get_history)
- [ChatMemory().get_message_count](#chatmemory()get_message_count)
- [ChatMemory().load](#chatmemory()load)
- [AgentMemory](#AgentMemory)
- [AgentMemory](#AgentMemory-1)
- [AgentMemory()._manage_overflow](#AgentMemory()_manage_overflow)
- [AgentMemory().add_message](#AgentMemory()add_message)
- [AgentMemory().copy](#AgentMemory()copy)
- [AgentMemory().dump](#AgentMemory()dump)
- [AgentMemory().get_history](#AgentMemory()get_history)
- [AgentMemory().get_message_count](#AgentMemory()get_message_count)
- [AgentMemory().load](#AgentMemory()load)
- [Message](#message)
- [print_panel](#print_panel)

## ChatMemory
## AgentMemory

[Show source in chat_memory.py:19](../../../../../atomic_agents/lib/components/chat_memory.py#L19)
[Show source in agent_memory.py:19](../../../../../atomic_agents/lib/components/agent_memory.py#L19)

Manages the chat history for an AI agent.

Expand All @@ -51,13 +51,13 @@ Manages the chat history for an AI agent.
#### Signature

```python
class ChatMemory:
class AgentMemory:
def __init__(self, max_messages: Optional[int] = None): ...
```

### ChatMemory()._manage_overflow
### AgentMemory()._manage_overflow

[Show source in chat_memory.py:61](../../../../../atomic_agents/lib/components/chat_memory.py#L61)
[Show source in agent_memory.py:61](../../../../../atomic_agents/lib/components/agent_memory.py#L61)

Manages the chat history overflow based on max_messages constraint.

Expand All @@ -67,17 +67,17 @@ Manages the chat history overflow based on max_messages constraint.
def _manage_overflow(self) -> None: ...
```

### ChatMemory().add_message
### AgentMemory().add_message

[Show source in chat_memory.py:38](../../../../../atomic_agents/lib/components/chat_memory.py#L38)
[Show source in agent_memory.py:38](../../../../../atomic_agents/lib/components/agent_memory.py#L38)

Adds a message to the chat history and manages overflow.

#### Arguments

- `role` *str* - The role of the message sender.
content (Union[str, Dict]): The content of the message.
- [tool_message](#chatmemory) *Optional[Dict]* - Optional tool message to be included.
- [tool_message](#AgentMemory) *Optional[Dict]* - Optional tool message to be included.
- `tool_id` *Optional[str]* - Optional unique identifier for the tool call.

#### Signature
Expand All @@ -92,25 +92,25 @@ def add_message(
) -> None: ...
```

### ChatMemory().copy
### AgentMemory().copy

[Show source in chat_memory.py:109](../../../../../atomic_agents/lib/components/chat_memory.py#L109)
[Show source in agent_memory.py:109](../../../../../atomic_agents/lib/components/agent_memory.py#L109)

Creates a copy of the chat memory.

#### Returns

- [ChatMemory](#chatmemory) - A copy of the chat memory.
- [AgentMemory](#AgentMemory) - A copy of the chat memory.

#### Signature

```python
def copy(self) -> "ChatMemory": ...
def copy(self) -> "AgentMemory": ...
```

### ChatMemory().dump
### AgentMemory().dump

[Show source in chat_memory.py:78](../../../../../atomic_agents/lib/components/chat_memory.py#L78)
[Show source in agent_memory.py:78](../../../../../atomic_agents/lib/components/agent_memory.py#L78)

Converts the chat history to a list of dictionaries.

Expand All @@ -124,9 +124,9 @@ Converts the chat history to a list of dictionaries.
def dump(self) -> List[Dict]: ...
```

### ChatMemory().get_history
### AgentMemory().get_history

[Show source in chat_memory.py:69](../../../../../atomic_agents/lib/components/chat_memory.py#L69)
[Show source in agent_memory.py:69](../../../../../atomic_agents/lib/components/agent_memory.py#L69)

Retrieves the chat history.

Expand All @@ -144,9 +144,9 @@ def get_history(self) -> List[Message]: ...

- [Message](#message)

### ChatMemory().get_message_count
### AgentMemory().get_message_count

[Show source in chat_memory.py:121](../../../../../atomic_agents/lib/components/chat_memory.py#L121)
[Show source in agent_memory.py:121](../../../../../atomic_agents/lib/components/agent_memory.py#L121)

Returns the number of messages in the chat history.

Expand All @@ -160,9 +160,9 @@ Returns the number of messages in the chat history.
def get_message_count(self) -> int: ...
```

### ChatMemory().load
### AgentMemory().load

[Show source in chat_memory.py:87](../../../../../atomic_agents/lib/components/chat_memory.py#L87)
[Show source in agent_memory.py:87](../../../../../atomic_agents/lib/components/agent_memory.py#L87)

Loads the chat history from a list of dictionaries using Pydantic's parsing.

Expand All @@ -180,7 +180,7 @@ def load(self, dict_list: List[Dict]) -> None: ...

## Message

[Show source in chat_memory.py:4](../../../../../atomic_agents/lib/components/chat_memory.py#L4)
[Show source in agent_memory.py:4](../../../../../atomic_agents/lib/components/agent_memory.py#L4)

Represents a message in the chat history.

Expand All @@ -201,7 +201,7 @@ class Message(BaseModel): ...

## print_panel

[Show source in chat_memory.py:139](../../../../../atomic_agents/lib/components/chat_memory.py#L139)
[Show source in agent_memory.py:139](../../../../../atomic_agents/lib/components/agent_memory.py#L139)

#### Signature

Expand Down
2 changes: 1 addition & 1 deletion docs/api/atomic_agents/lib/components/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@

## Modules

- [ChatMemory](./chat_memory.md)
- [AgentMemory](./agent_memory.md)
- [SystemPromptGenerator](./system_prompt_generator.md)
4 changes: 2 additions & 2 deletions examples/basic_custom_chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import os
from rich.console import Console
from atomic_agents.lib.components.chat_memory import ChatMemory
from atomic_agents.lib.components.agent_memory import AgentMemory
from atomic_agents.agents.base_chat_agent import BaseChatAgent, BaseChatAgentConfig
from atomic_agents.lib.components.system_prompt_generator import SystemPromptGenerator, SystemPromptInfo
import instructor
Expand All @@ -29,7 +29,7 @@
system_prompt_generator = SystemPromptGenerator(system_prompt)

# Initialize chat memory to store conversation history
memory = ChatMemory()
memory = AgentMemory()
# Define initial memory with a greeting message from the assistant
initial_memory = [
{'role': 'assistant', 'content': 'How do you do? What can I do for you? Tell me, pray, what is your need today?'}
Expand Down
14 changes: 7 additions & 7 deletions examples/memory_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
from rich.text import Text
from rich.table import Table

from atomic_agents.lib.components.chat_memory import ChatMemory
from atomic_agents.lib.components.agent_memory import AgentMemory

console = Console()

def print_panel(title, content):
console.print(Panel(content, title=title, expand=False, border_style="cyan"))

# Create a ChatMemory with a maximum of 5 messages
memory = ChatMemory(max_messages=5)
# Create a AgentMemory with a maximum of 5 messages
memory = AgentMemory(max_messages=5)

console.print("[bold magenta]ChatMemory Test Cases[/bold magenta]", justify="center")
console.print("[bold magenta]AgentMemory Test Cases[/bold magenta]", justify="center")
console.print()

# Test Case 1
Expand Down Expand Up @@ -67,7 +67,7 @@ def print_panel(title, content):
content.append("Dumped data:\n")
content.append(str(dumped_data), style="dim")
content.append("\n\n")
new_memory = ChatMemory(max_messages=5)
new_memory = AgentMemory(max_messages=5)
new_memory.load(dumped_data)
content.append("Loaded memory:\n")
for msg in new_memory.get_history():
Expand All @@ -91,7 +91,7 @@ def print_panel(title, content):
large_buffer = [
{"role": "user", "content": f"Message {i}"} for i in range(10)
]
large_memory = ChatMemory(max_messages=5)
large_memory = AgentMemory(max_messages=5)
large_memory.load(large_buffer)
content.append(f"Total messages after loading large buffer: {large_memory.get_message_count()}\n\n")
content.append("Current history (should only have 5 most recent messages):\n")
Expand All @@ -101,7 +101,7 @@ def print_panel(title, content):

# Test Case 8
content = Text()
mixed_memory = ChatMemory(max_messages=10)
mixed_memory = AgentMemory(max_messages=10)
mixed_memory.add_message("user", "Hello")
mixed_memory.add_message("assistant", {"text": "Hi there!", "confidence": 0.95})
mixed_memory.add_message("system", {"command": "reset_conversation"})
Expand Down
Loading