fix: unstuck agent after tool calls, display completed streams
This commit is contained in:
1 parent
c9a76e7fb3
commit
161dfd507f
4 files changed
+11
-3
No files matched your search
@@ -66,6 +66,7 @@ class Agent:
|
||||
agent_run.close()
|
||||
raise NotImplementedError("Subclasses must implement run()")
|
||||
|
||||
# Deprecate this. This is just run with extra baggage.
|
||||
async def prompt(self, instruction, input=None, **kwargs):
|
||||
run = AgentRun.create(
|
||||
self.app,
|
||||
|
||||
@@ -40,6 +40,9 @@ async def chat_completion_loop(app, run, messages, model_id=None, tools=None):
|
||||
|
||||
run.emit_event('inference', msg)
|
||||
|
||||
# Broken generator with no output
|
||||
else: break
|
||||
|
||||
for tc in tool_calls:
|
||||
tool = next((t for t in tools if t.name == tc.tool_name), None)
|
||||
if tool is None:
|
||||
@@ -50,8 +53,9 @@ async def chat_completion_loop(app, run, messages, model_id=None, tools=None):
|
||||
else:
|
||||
tc.tool = tool
|
||||
|
||||
# By default, end if there's no calls
|
||||
else: break
|
||||
# If not calling must output something useful
|
||||
else:
|
||||
if turn_response: break
|
||||
|
||||
run.close()
|
||||
|
||||
|
||||
+1
-1
@@ -149,7 +149,7 @@ class Tool:
|
||||
|
||||
@classmethod
|
||||
def tool_name(cls):
|
||||
return ''.join(['_'+c.lower() if c.isupper() else c for c in cls.__name__]).lstrip('_')
|
||||
return ''.join(['-'+c.lower() if c.isupper() else c for c in cls.__name__]).lstrip('_')
|
||||
|
||||
|
||||
def _generate_spec(self):
|
||||
|
||||
@@ -20,7 +20,10 @@ def encode_value(value):
|
||||
json['result'] = encode_value(value.result),
|
||||
return json
|
||||
elif isinstance(value, Stream):
|
||||
if value.open:
|
||||
return {'streamId': value.id}
|
||||
else:
|
||||
return value.content
|
||||
else:
|
||||
return value
|
||||
|
||||
|
||||
Reference in new issue
Block a user