Skip to content

πŸ™Œ OpenHands: AI-Driven Development

minor fixes for langchain agent (#83)

Robert Brennan78f875224624
diff --git a/agenthub/langchains_agent/utils/agent.py b/agenthub/langchains_agent/utils/agent.py
index 2bd8fe10f8..2c310a61fa 100644
--- a/agenthub/langchains_agent/utils/agent.py
+++ b/agenthub/langchains_agent/utils/agent.py
@@ -14,6 +14,8 @@ class Agent:
self.memory = LongTermMemory()
def add_event(self, event):
+ if 'output' in event.args:
+ event.args['output'] = event.args['output'][:MAX_OUTPUT_LENGTH] + "..."
self.monologue.add_event(event)
self.memory.add_event(event)
if self.monologue.get_total_length() > MAX_MONOLOGUE_LENGTH:
@@ -26,6 +28,9 @@ class Agent:
self.model_name,
cmd_mgr.background_commands
)
+ if action_dict is None:
+ # TODO: this seems to happen if the LLM response isn't valid JSON. Maybe it should be an `error` instead? How should we handle this case?
+ return Event('think', {'thought': '...'})
event = Event(action_dict['action'], action_dict['args'])
self.latest_action = event
return event
diff --git a/opendevin/controller.py b/opendevin/controller.py
index 4852644a70..e9ffb93b4a 100644
--- a/opendevin/controller.py
+++ b/opendevin/controller.py
@@ -2,7 +2,7 @@ from opendevin.lib.command_manager import CommandManager
from opendevin.lib.event import Event
def print_callback(event):
- print(event, flush=True)
+ print(event.str_truncated(), flush=True)
class AgentController:
def __init__(self, agent, workdir, max_iterations=100, callbacks=[]):
diff --git a/opendevin/lib/event.py b/opendevin/lib/event.py
index 3732f87f44..d0d3cc56e9 100644
--- a/opendevin/lib/event.py
+++ b/opendevin/lib/event.py
@@ -2,7 +2,7 @@ import os
import json
import opendevin.lib.actions as actions
-ACTION_TYPES = ['run', 'kill', 'browse', 'read', 'write', 'recall', 'think', 'output', 'error', 'finish']
+ACTION_TYPES = ['run', 'kill', 'browse', 'read', 'write', 'recall', 'think', 'summarize', 'output', 'error', 'finish']
RUNNABLE_ACTIONS = ['run', 'kill', 'browse', 'read', 'write', 'recall']
class Event:
@@ -15,6 +15,12 @@ class Event:
def __str__(self):
return self.action + " " + str(self.args)
+ def str_truncated(self, max_len=1000):
+ s = str(self)
+ if len(s) > max_len:
+ s = s[:max_len] + '...'
+ return s
+
def to_dict(self):
return {
'action': self.action,