Compare commits

..

2 Commits

Author SHA1 Message Date
daniel
f31d732cb9 Read model-id from SSM and pass to BedrockModel in main.py 2026-05-15 06:58:54 -05:00
daniel
62862f00f0 Make agent and compaction model IDs configurable via SSM 2026-05-14 18:27:35 -05:00
4 changed files with 37 additions and 3 deletions

View File

@@ -0,0 +1,25 @@
"""Config loader — fetches model IDs from SSM Parameter Store at cold start."""
import boto3
_DEFAULTS = {
'/agent-claw/config/agent_model_id': 'us.anthropic.claude-sonnet-4-6',
'/agent-claw/config/compaction_model_id': 'us.anthropic.claude-3-5-haiku-20241022-v1:0',
}
def _load():
ssm = boto3.client('ssm', region_name='us-east-1')
names = list(_DEFAULTS.keys())
try:
resp = ssm.get_parameters(Names=names)
found = {p['Name']: p['Value'] for p in resp['Parameters']}
except Exception:
found = {}
return {name: found.get(name, default) for name, default in _DEFAULTS.items()}
_params = _load()
AGENT_MODEL_ID: str = _params['/agent-claw/config/agent_model_id']
COMPACTION_MODEL_ID: str = _params['/agent-claw/config/compaction_model_id']

View File

@@ -11,6 +11,7 @@ from bedrock_agentcore.runtime import BedrockAgentCoreApp
from channels.telegram import TelegramAdapter from channels.telegram import TelegramAdapter
from prompt_builder import build_system_prompt, invalidate_prompt from prompt_builder import build_system_prompt, invalidate_prompt
import memory_manager import memory_manager
import config
from tools import web as web_tools from tools import web as web_tools
from tools import workspace as ws_tools from tools import workspace as ws_tools
from tools import messaging from tools import messaging
@@ -378,7 +379,7 @@ async def main(payload: dict, context):
# NOTE: extended thinking disabled — causes retry/duplicate issues with streaming # NOTE: extended thinking disabled — causes retry/duplicate issues with streaming
from botocore.config import Config as BotoConfig from botocore.config import Config as BotoConfig
model = BedrockModel( model = BedrockModel(
model_id="us.anthropic.claude-sonnet-4-6", model_id=config.AGENT_MODEL_ID,
region_name="us-east-1", region_name="us-east-1",
boto_client_config=BotoConfig(read_timeout=600, connect_timeout=10), boto_client_config=BotoConfig(read_timeout=600, connect_timeout=10),
) )

View File

@@ -10,13 +10,14 @@ import boto3
from bedrock_agentcore.memory.client import MemoryClient from bedrock_agentcore.memory.client import MemoryClient
import config
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
MEMORY_ID = 'agentclaw_AgentClawMemory-i7Csf776AH' MEMORY_ID = 'agentclaw_AgentClawMemory-i7Csf776AH'
SESSION_WINDOW_SIZE = 100 SESSION_WINDOW_SIZE = 100
USERS_TABLE_NAME = os.environ.get('USERS_TABLE_NAME', 'agent-claw-users') USERS_TABLE_NAME = os.environ.get('USERS_TABLE_NAME', 'agent-claw-users')
LTM_SESSION_ID = 'ltm-extractions' LTM_SESSION_ID = 'ltm-extractions'
HAIKU_MODEL_ID = 'us.anthropic.claude-3-5-haiku-20241022-v1:0'
_memory_client: MemoryClient | None = None _memory_client: MemoryClient | None = None
@@ -110,7 +111,7 @@ def _call_claude_extraction(conversation_text: str) -> dict:
'Conversation:\n' + conversation_text 'Conversation:\n' + conversation_text
) )
resp = bedrock.converse( resp = bedrock.converse(
modelId=HAIKU_MODEL_ID, modelId=config.COMPACTION_MODEL_ID,
messages=[{'role': 'user', 'content': [{'text': prompt}]}], messages=[{'role': 'user', 'content': [{'text': prompt}]}],
inferenceConfig={'maxTokens': 1024}, inferenceConfig={'maxTokens': 1024},
) )

View File

@@ -4,7 +4,9 @@ agent-claw Runtime 1 — main assistant agent.
Entrypoint for AgentCore CodeZip deployment. Entrypoint for AgentCore CodeZip deployment.
""" """
import os import os
import boto3
from strands import Agent, tool from strands import Agent, tool
from strands.models import BedrockModel
from bedrock_agentcore.runtime import BedrockAgentCoreApp from bedrock_agentcore.runtime import BedrockAgentCoreApp
from channels.telegram import TelegramAdapter from channels.telegram import TelegramAdapter
@@ -15,6 +17,10 @@ from tools import messaging
app = BedrockAgentCoreApp() app = BedrockAgentCoreApp()
# Read model ID from SSM once at module load (cached for warm invocations)
_ssm = boto3.client("ssm", region_name=os.environ.get("AWS_REGION_NAME", "us-east-1"))
_model_id = _ssm.get_parameter(Name="/agent-claw/model-id")["Parameter"]["Value"]
# ── Tool definitions ────────────────────────────────────────────────────── # ── Tool definitions ──────────────────────────────────────────────────────
@@ -77,6 +83,7 @@ def main(payload: dict, context) -> dict:
# Create and run Strands agent # Create and run Strands agent
agent = Agent( agent = Agent(
model=BedrockModel(model_id=_model_id),
system_prompt=system_prompt, system_prompt=system_prompt,
tools=[send_message, web_search, web_fetch, read_workspace_file, write_workspace_file], tools=[send_message, web_search, web_fetch, read_workspace_file, write_workspace_file],
) )