To avoid 'context bloat' and optimize for cost and capability, you can break complex workflows into specialized Agent instances called subagents.
By passing a list of subagents to the agents parameter of a 'supervisor' agent, the supervisor can delegate tasks. The supervisor decides which subagent to call based on the subagent's name and description.
Key configuration for subagents:
name: A unique identifier for the agent.description: A text explanation of what the agent does (used by the supervisor for routing).tool_settings: Defines which tools the agent can access via ToolSettings, LocalToolSettings, and ToolAllowlist.
from splunklib.ai import Agent, OpenAIModel
from splunklib.ai.messages import HumanMessage
from splunklib.ai.tool_settings import LocalToolSettings, ToolAllowlist, ToolSettings
from splunklib.client import connect
model = OpenAIModel(...)
service = connect(...)
# Define specialized subagents
async with (
Agent(
model=highly_specialized_model,
service=service,
system_prompt="You are a highly specialized debugging agent...",
name="debugging_agent",
description="Agent, that provided with logs will analyze and debug complex issues",
tool_settings=ToolSettings(
local=LocalToolSettings(allowlist=ToolAllowlist(tags=["debugging"])),
remote=None,
),
) as debugging_agent,
Agent(
model=low_cost_model,
service=service,
system_prompt="You are a log analyzer agent...",
name="log_analyzer_agent",
description="Agent, that provided with a problem details will return logs...",
tool_settings=ToolSettings(
local=LocalToolSettings(allowlist=ToolAllowlist(tags=["spl"])),
remote=None,
),
),
) as (debugging_agent, log_analyzer_agent):
# The supervisor agent uses the subagents to perform tasks
async with Agent(
model=low_cost_model,
service=service,
system_prompt="You are a supervisor agent, use available subagents to perform requested operations.",
agents=[debugging_agent, log_analyzer_agent],
) as agent:
result = await agent.invoke(
[
HumanMessage(
content="Query the logs in the index 'main', and try to debug the root cause of this issue."
)
]
)