Repository navigation
feat(delegate): File-based agent definitions with markdown + YAML frontmatter #2183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ba87b4e
first version MD agents
VascoSch92 ce6b225
update
VascoSch92 475881c
update
VascoSch92 6d892f7
update after discussion
VascoSch92 e0fb41b
all-hands bot feedback
VascoSch92 455c8ff
roasted-review feedback
VascoSch92 0754db0
docstrings
VascoSch92 ea1863e
add example
VascoSch92 36fdf3e
change number of example
VascoSch92 d38a9e5
Apply suggestion from @enyst
enyst b1495ad
comments and feedback
VascoSch92 6fe32d4
Merge branch 'main' into vasco/issue-2049
VascoSch92 03e4cda
fix after rebase and discussion
VascoSch92 b33defb
nit
VascoSch92 1aace23
fix tests
VascoSch92 d40971b
Merge branch 'main' into vasco/issue-2049
VascoSch92 38acb66
fix after rebase
VascoSch92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| """Example: Defining a sub-agent inline with AgentDefinition. | ||
|
|
||
| Defines a grammar-checker sub-agent using AgentDefinition, registers it, | ||
| and delegates work to it from an orchestrator agent. The orchestrator then | ||
| asks the builtin default agent to judge the results. | ||
| """ | ||
|
|
||
| import os | ||
| from pathlib import Path | ||
|
|
||
| from openhands.sdk import ( | ||
| LLM, | ||
| Agent, | ||
| Conversation, | ||
| Tool, | ||
| agent_definition_to_factory, | ||
| register_agent, | ||
| ) | ||
| from openhands.sdk.subagent import AgentDefinition | ||
| from openhands.sdk.tool import register_tool | ||
| from openhands.tools.delegate import DelegateTool, DelegationVisualizer | ||
|
|
||
|
|
||
| # 1. Define a sub-agent using AgentDefinition | ||
| grammar_checker = AgentDefinition( | ||
| name="grammar-checker", | ||
| description="Checks documents for grammatical errors.", | ||
| tools=["file_editor"], | ||
| system_prompt="You are a grammar expert. Find and list grammatical errors.", | ||
| ) | ||
|
|
||
| # 2. Register it in the delegate registry | ||
| register_agent( | ||
| name=grammar_checker.name, | ||
| factory_func=agent_definition_to_factory(grammar_checker), | ||
| description=grammar_checker.description, | ||
| ) | ||
|
|
||
| # 3. Set up the orchestrator agent with the DelegateTool | ||
| llm = LLM( | ||
| model=os.getenv("LLM_MODEL", "anthropic/claude-sonnet-4-5-20250929"), | ||
| api_key=os.getenv("LLM_API_KEY"), | ||
| base_url=os.getenv("LLM_BASE_URL"), | ||
| usage_id="file-agents-demo", | ||
| ) | ||
|
|
||
| register_tool("DelegateTool", DelegateTool) | ||
| main_agent = Agent( | ||
| llm=llm, | ||
| tools=[Tool(name="DelegateTool")], | ||
| ) | ||
| conversation = Conversation( | ||
| agent=main_agent, | ||
| workspace=Path.cwd(), | ||
| visualizer=DelegationVisualizer(name="Orchestrator"), | ||
| ) | ||
|
|
||
| # 4. Ask the orchestrator to delegate to our agent | ||
| task = ( | ||
| "Please delegate to the grammar-checker agent and ask it to review " | ||
| "the README.md file in search of grammatical errors.\n" | ||
| "Then ask the default agent to judge the errors." | ||
| ) | ||
| conversation.send_message(task) | ||
| conversation.run() | ||
|
|
||
| cost = conversation.conversation_stats.get_combined_metrics().accumulated_cost | ||
| print(f"\nTotal cost: ${cost:.4f}") | ||
| print(f"EXAMPLE_COST: {cost:.4f}") |
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.