chrisjcc commited on
Commit
31861cb
·
1 Parent(s): 709349e

Integrated the SlidingWindowConversationManager into app.py.

Browse files

The agent is now configured to:

Keep a window of the last 20 messages.
Truncate large tool outputs to prevent context overflow.

Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -55,6 +55,7 @@ from fastapi.middleware.cors import CORSMiddleware
55
  from pydantic import BaseModel
56
 
57
  from strands import Agent
 
58
  from strands.models.openai import OpenAIModel
59
 
60
  # Import confluence-ingestor
@@ -390,10 +391,22 @@ def create_enhanced_agent():
390
  model_id="gpt-4o",
391
  params={"temperature": 0.1, "max_tokens": 2048},
392
  )
393
- _cached_agent = Agent(model=model, system_prompt=system_prompt, tools=tools)
 
 
 
 
 
 
394
  else:
395
- _cached_agent = Agent(system_prompt=system_prompt, tools=tools)
396
-
 
 
 
 
 
 
397
  return _cached_agent
398
 
399
 
 
55
  from pydantic import BaseModel
56
 
57
  from strands import Agent
58
+ from strands.agent.conversation_manager import SlidingWindowConversationManager
59
  from strands.models.openai import OpenAIModel
60
 
61
  # Import confluence-ingestor
 
391
  model_id="gpt-4o",
392
  params={"temperature": 0.1, "max_tokens": 2048},
393
  )
394
+ # Create a conversation manager with custom window size
395
+ conversation_manager = SlidingWindowConversationManager(
396
+ window_size=20, # Maximum number of messages to keep
397
+ should_truncate_results=True, # Enable truncating the tool result when a message is too large for the model's context window
398
+ )
399
+
400
+ _cached_agent = Agent(model=model, system_prompt=system_prompt, tools=tools, conversation_manager=conversation_manager)
401
  else:
402
+ # Create a conversation manager with custom window size
403
+ conversation_manager = SlidingWindowConversationManager(
404
+ window_size=20, # Maximum number of messages to keep
405
+ should_truncate_results=True, # Enable truncating the tool result when a message is too large for the model's context window
406
+ )
407
+
408
+ _cached_agent = Agent(system_prompt=system_prompt, tools=tools, conversation_manager=conversation_manager)
409
+
410
  return _cached_agent
411
 
412