Skip to content

Commit ae697e8

Browse files
authored
fix(chat): store trajectory history, remove final_answer event (#1295)
Signed-off-by: Radek Ježek <radek.jezek@ibm.com>
1 parent 765025e commit ae697e8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

agents/chat/src/chat/agent.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,18 @@ async def chat(
292292
continue
293293

294294
last_step = event.state.steps[-1] if event.state.steps else None
295-
if last_step and last_step.tool is not None:
295+
if last_step and last_step.tool is not None and last_step.tool.name != FinalAnswerTool.name:
296296
trajectory_content = TrajectoryContent(
297297
input=last_step.input,
298298
output=last_step.output,
299299
error=last_step.error,
300300
)
301-
yield trajectory.trajectory_metadata(
301+
metadata = trajectory.trajectory_metadata(
302302
title=last_step.tool.name,
303303
content=trajectory_content.model_dump_json(),
304304
)
305+
yield metadata
306+
await context.store(AgentMessage(metadata=metadata))
305307

306308
if isinstance(last_step.output, FileCreatorToolOutput):
307309
result = last_step.output.result
@@ -338,5 +340,6 @@ def serve():
338340
except KeyboardInterrupt:
339341
pass
340342

343+
341344
if __name__ == "__main__":
342345
serve()

0 commit comments

Comments
 (0)