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