Skip to content

Conversation

@gadenbuie
Copy link
Collaborator

Create a hierarchical agent workflow system that allows an orchestrating LLM agent to delegate tasks to specialized subagents with their own LLM chat sessions. Subagents maintain conversation state, can be resumed across multiple tool calls, and have configurable tool access.

Quick summary of features

  • Persistent Sessions: Subagent conversations can be resumed using word-based IDs (e.g., "stable-genius", "galavanting-aardvark")
  • Return Value: Final assistant message text + session ID for continuation
  • Tool Listing: Dynamic - generated at runtime from available registered tools
  • Cleanup: Session-scoped - sessions persist until R session ends
  • Configurable: use btw.subagent.client to choose the ellmer client, btw.subagent.tools_default for default attached tools and btw.subagent.tools_allowed to limit to specific allowed tools in subagents.

Note: these options currently only work as R options and aren't supported in btw.md (yet)

Comment on lines +337 to +342
# Build tool groups summary
if (length(tool_groups) > 0) {
tool_summary <- paste(
"\n\nAvailable tool groups:",
paste(tool_groups, collapse = ", ")
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent here was to include individual tool names and a preview of the description, not just a list of tool group names.

Comment on lines 252 to 256
# Determine the tools to use (applying defaults)
configured_tools <-
tools %||%
getOption("btw.subagent.tools_default") %||%
getOption("btw.tools")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with reading options here is that if an option is set via btw.md it's scope is just btw_client(), so by the time the the subagent tool runs and hits this code path, the options declared in btw.md have been unset. We'll need a way to create the tool attached via btw_client() such that it retains these options so they don't need to be check anew.

Copy link
Collaborator

@simonpcouch simonpcouch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is stellar. Only providing the last assistant message as the output, allowing the main agent to configure which tools the subagent will access to, the tool UI, etc.

The only additional feature that I might consider is allowing the main agent to toggle whether the subagent should inherit the turns from the main agent. There are many situations where I'm fine to pay for the cost of the subagents "re-reading" tokens in exchange for it knowing enough to do the task right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants