Open
Description
Question
Hi, I was migrating my old composer implementation to history_processors
based composer and found that I couldn't save the results processed by history_processors
, which resulted in each tool return triggering the compact.
I'm now implementing this using a rather tricky way: transfer via ctx
with a patched_messages
field
ctx = AgentContext()
async with agent.iter(..., deps=ctx) as run:
async for node in run:
if Agent.is_user_prompt_node(node) or Agent.is_end_node(node):
continue
elif Agent.is_model_request_node(node) or Agent.is_call_tools_node(node):
async with node.stream(run.ctx) as request_stream:
# Right after request, save immediately
run.ctx.state.message_history = ctx.patched_messages if ctx.patched_messages else ...
# Then start streaming
async for event in request_stream:
...
Releated
- feat: add
history_processors
parameter toAgent
for message processing #1970 - feat: add RunContext support to history processors #2002
What do you think? I intuit that history_processors
will change message history.
cc @Kludex
Additional Context
No response