Skip to content

Commit

Permalink
Merge pull request #280 from crestalnetwork/feat/owner-mode
Browse files Browse the repository at this point in the history
Feat: clean memory after agent update
  • Loading branch information
taiyangc authored Feb 24, 2025
2 parents ad1b52d + 1b719b7 commit c9178b7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions app/admin/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ async def _process_agent(
if agent_data and agent_data.cdp_wallet_data:
has_wallet = True
wallet_data = json.loads(agent_data.cdp_wallet_data)
# Clean agent memory
await clean_agent_memory(latest_agent.id, clean_agent_memory=True)

if not has_wallet:
# create the wallet
Expand Down Expand Up @@ -131,9 +133,9 @@ async def _process_agent(
{"title": "Name", "short": True, "value": latest_agent.name},
{"title": "Model", "short": True, "value": latest_agent.model},
{
"title": "Enso Enabled",
"title": "GOAT Enabled",
"short": True,
"value": str(latest_agent.enso_enabled),
"value": str(latest_agent.goat_enabled),
},
{
"title": "CDP Enabled",
Expand Down
1 change: 1 addition & 0 deletions app/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def __init__(self):
self.deepseek_api_key = self.load("DEEPSEEK_API_KEY")
self.xai_api_key = self.load("XAI_API_KEY")
self.system_prompt = self.load("SYSTEM_PROMPT")
self.input_token_limit = int(self.load("INPUT_TOKEN_LIMIT", "60000"))
# Telegram server settings
self.tg_base_url = self.load("TG_BASE_URL")
self.tg_server_host = self.load("TG_SERVER_HOST", "127.0.0.1")
Expand Down
9 changes: 7 additions & 2 deletions app/core/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async def initialize_agent(aid):
raise HTTPException(status_code=500, detail=str(e))

# ==== Initialize LLM.
input_token_limit = 120000
input_token_limit = config.input_token_limit
# TODO: model name whitelist
if agent.model.startswith("deepseek"):
llm = ChatOpenAI(
Expand All @@ -136,7 +136,8 @@ async def initialize_agent(aid):
temperature=agent.temperature,
timeout=300,
)
input_token_limit = 60000
if input_token_limit > 60000:
input_token_limit = 60000
elif agent.model.startswith("grok"):
llm = ChatXAI(
model_name=agent.model,
Expand All @@ -146,6 +147,8 @@ async def initialize_agent(aid):
temperature=agent.temperature,
timeout=180,
)
if input_token_limit > 120000:
input_token_limit = 120000
else:
llm = ChatOpenAI(
model_name=agent.model,
Expand All @@ -155,6 +158,8 @@ async def initialize_agent(aid):
temperature=agent.temperature,
timeout=180,
)
if input_token_limit > 120000:
input_token_limit = 120000

# ==== Store buffered conversation history in memory.
memory = AsyncPostgresSaver(get_pool())
Expand Down

0 comments on commit c9178b7

Please sign in to comment.