Skip to content

Save history_processors's result for next round model request #2095

Open
@Wh1isper

Description

@Wh1isper

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

What do you think? I intuit that history_processors will change message history.

cc @Kludex

Additional Context

No response

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions