Skip to content

Commit 5167f1d

Browse files
committed
feat: new reset agent methods
Signed-off-by: Valentin De Matos <[email protected]>
1 parent e6e01e4 commit 5167f1d

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

agentarium/Agent.py

+10-16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import aisuite as ai
66

77
from enum import Enum
8+
from copy import deepcopy
89
from typing import List, Callable
910
from faker import Faker
1011
from .Interaction import Interaction
@@ -123,9 +124,9 @@ def __init__(self, **kwargs):
123124
self.agent_informations["bio"] = Agent._generate_agent_bio(self.agent_informations)
124125

125126
self._interaction_manager.register_agent(self)
126-
self._act_prompt = Agent._default_act_prompt
127+
self._act_prompt = deepcopy(Agent._default_act_prompt)
127128

128-
self._actions = Agent._default_actions
129+
self._actions = deepcopy(Agent._default_actions)
129130
self._actions["TALK"]["function"] = self._talk_action_function
130131
self._actions["THINK"]["function"] = self._think_action_function
131132

@@ -271,7 +272,6 @@ def act(self) -> str:
271272
response = llm_client.chat.completions.create(
272273
model=f"{config.llm_provider}:{config.llm_model}",
273274
messages=[
274-
{"role": "system", "content": "You are a helpful assistant."},
275275
{"role": "user", "content": prompt},
276276
],
277277
temperature=0.4,
@@ -283,19 +283,6 @@ def act(self) -> str:
283283
if actions[0] in self._actions:
284284
return self._actions[actions[0]]["function"](*actions[1:])
285285

286-
# if actions[0] == "TALK":
287-
# if len(actions) < 3:
288-
# raise RuntimeError(f"Received a TALK action with less than 3 arguments: {actions}")
289-
290-
# if (receiver := self._interaction_manager.get_agent(actions[1])) is None:
291-
# raise RuntimeError(f"Received a TALK action with an invalid agent ID: {actions[1]}")
292-
293-
# return self.talk_to(receiver, actions[2])
294-
295-
# elif actions[0] == "THINK":
296-
# # NOTE: This is a self-interaction, but maybe we should add a way to handle self-thinking.
297-
# return self._interaction_manager.record_interaction(self, self, actions[1])
298-
299286
raise RuntimeError(f"Invalid action: '{actions[0]}'. Received output: {response.choices[0].message.content}")
300287

301288
def dump(self) -> dict:
@@ -505,6 +492,13 @@ def wrapper(*args, **kwargs):
505492
self._actions[name] = action_descriptor
506493
self._actions[name]["function"] = standardize_action_output(action_function)
507494

495+
def reset(self) -> None:
496+
"""
497+
Reset the agent's state.
498+
"""
499+
self._interaction_manager.reset_agent(self)
500+
self.storage = {}
501+
508502

509503
if __name__ == "__main__":
510504

agentarium/AgentInteractionManager.py

+6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ def register_agent(self, agent: Agent) -> None:
6060
self._agents[agent.agent_id] = agent
6161
self._agent_private_interactions[agent.agent_id] = []
6262

63+
def reset_agent(self, agent: Agent) -> None:
64+
"""
65+
Reset the agent's state.
66+
"""
67+
self._agent_private_interactions[agent.agent_id] = []
68+
6369
def get_agent(self, agent_id: str) -> Agent | None:
6470
"""
6571
Retrieve an agent by their ID.

agentarium/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .AgentInteractionManager import AgentInteractionManager
44
from .Interaction import Interaction
55

6-
__version__ = "0.1.0"
6+
__version__ = "0.2.0"
77

88
__all__ = [
99
"Agent",

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "agentarium"
7-
version = "0.1.2"
7+
version = "0.2.0"
88
authors = [
99
{ name = "thytu" },
1010
]

0 commit comments

Comments
 (0)