feat: #858 add include_conversation_history to Agent.as_tool() #3391
Closed
0xSudoSSH wants to merge 1 commit into
Closed
feat: #858 add include_conversation_history to Agent.as_tool() #33910xSudoSSH wants to merge 1 commit into
0xSudoSSH wants to merge 1 commit into
Conversation
Pass parent conversation history to sub-agents via a summarized <CONVERSATION HISTORY> block, reusing handoff nesting logic. Closes openai#858
Member
|
Thanks for sharing this idea, but we intentionally avoid adding this feature. The mentioned issue should be closed, so I will do so later. |
Contributor
Author
@seratch Thanks for the quick feedback! I understand the design intent to keep as_tool and handoffs distinct. I'm relatively new to open source contributing but enjoyed working on this codebase (my first merged PR was #3339). Are there any open issues — ideally small to medium in scope — where contributions would be welcome? Happy to help with bug fixes or smaller features that align with the team's roadmap. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
include_conversation_historyparameter toAgent.as_tool()that passes the parent's conversation history to the sub-agent as a<CONVERSATION HISTORY>summary, matching the format used by handoff history nesting.This addresses the gap between handoffs (full history, no return) and
as_tool()(no history, returns control) by allowing sub-agents to see the full conversation context while still returning results to the orchestrator.API:
include_conversation_historyis optional, defaults toFalse— fully backward compatible.What the sub-agent receives:
<CONVERSATION HISTORY>text summary of the full parent conversation (including tool calls/results)Implementation:
ToolExecutionContextcaptures conversation state (input_history,pre_step_items,new_step_items) before tool execution inexecute_tools_and_side_effects:build_agent_tool_history()reuses a shared_build_history()helper extracted fromnest_handoff_history(), ensuring consistent summarization_should_forward_pre_item(strict) for previous turns,_should_forward_new_item(permissive) for current turn_execute_tool_planto prevent stale stateRunStateon the first run, so resuming from approval interruptions preserves full context without re-prependingFiles changed:
src/agents/run_context.py—ToolExecutionContextdataclass + field onRunContextWrappersrc/agents/run_internal/turn_resolution.py— set/cleartool_execution_contextsrc/agents/handoffs/history.py— extract_build_historyshared helper + addbuild_agent_tool_historysrc/agents/agent.py—include_conversation_historyparam + prepend logic in_run_agent_implsrc/agents/tool_context.py— accepttool_execution_contextin constructorTest plan
make format,make lint,make typecheck— all passexamples/agent_patterns/agents_as_tools_with_history.pyIssue number
Closes #858
Checks
make lintandmake format