Skip to content

Commit c890583

Browse files
authored
Allow resumption of subagents (#102)
1 parent fd2b744 commit c890583

6 files changed

Lines changed: 414 additions & 57 deletions

File tree

splunklib/ai/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,46 @@ for a given task and should be called.
415415
The input and output schemas are defined as `pydantic.BaseModel` classes and passed to the
416416
`Agent` constructor via the `input_schema` and `output_schema` parameters.
417417

418+
## Subagents with ConversationStore
419+
420+
A subagent can be given its own `conversation_store`, enabling multi-turn conversations between
421+
the supervisor and the subagent. When a subagent has a store, the supervisor can resume prior
422+
conversations with an subagent.
423+
424+
```py
425+
from splunklib.ai import Agent, OpenAIModel
426+
from splunklib.ai.conversation_store import InMemoryStore
427+
from splunklib.ai.messages import HumanMessage
428+
from splunklib.client import connect
429+
430+
model = OpenAIModel(...)
431+
service = connect(...)
432+
433+
async with (
434+
Agent(
435+
model=model,
436+
service=service,
437+
system_prompt=(
438+
"You are a log analysis expert. When asked to analyze a problem, "
439+
"ask clarifying questions if needed before querying logs."
440+
),
441+
name="log_analyzer_agent",
442+
description="Analyzes logs and can ask follow-up questions to narrow down a problem.",
443+
conversation_store=InMemoryStore(),
444+
) as log_analyzer_agent,
445+
):
446+
async with Agent(
447+
model=model,
448+
service=service,
449+
system_prompt="You are a supervisor. Use the log analyzer agent to investigate issues.",
450+
agents=[log_analyzer_agent],
451+
) as agent:
452+
# The supervisor calls the subagent and may continue the
453+
# same conversation with a subagent in the agentic loop and
454+
# across multiple agent loop invocations.
455+
await agent.invoke(...)
456+
```
457+
418458
### Structured output
419459

420460
An `Agent` can be configured to return structured output. This allows applications to parse results deterministically

0 commit comments

Comments
 (0)