minor fixes for langchain agent (#83)

* minor fixes

* set max output len

* truncate logs

* Update agenthub/langchains_agent/utils/agent.py
This commit is contained in:
Robert Brennan
2024-03-23 17:34:35 -04:00
committed by GitHub
parent 0b5a531518
commit 78f8752246
3 changed files with 13 additions and 2 deletions

View File

@@ -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

View File

@@ -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=[]):

View File

@@ -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,