-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy path49_include_contents.py
More file actions
81 lines (65 loc) · 2.56 KB
/
Copy path49_include_contents.py
File metadata and controls
81 lines (65 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Copyright (c) 2025 Agentspan
# Licensed under the MIT License. See LICENSE file in the project root for details.
"""Include Contents — control context passed to sub-agents.
When ``include_contents="none"``, a sub-agent starts with a clean slate
and does NOT see the parent agent's conversation history. This is useful
for sub-agents that should work independently without being influenced
by prior messages.
Requirements:
- Conductor server with include_contents support
- AGENTSPAN_SERVER_URL=http://localhost:8080/api as environment variable
- AGENTSPAN_LLM_MODEL=openai/gpt-4o-mini as environment variable
"""
from conductor.ai.agents import Agent, AgentRuntime, tool
from settings import settings
@tool
def summarize_text(text: str) -> dict:
"""Summarize a piece of text.
Args:
text: The text to summarize.
Returns:
Dictionary with the summary.
"""
words = text.split()
return {"summary": " ".join(words[:20]) + "...", "word_count": len(words)}
# This sub-agent won't see the parent's conversation history
independent_summarizer = Agent(
name="independent_summarizer_49",
model=settings.llm_model,
instructions="You are a summarizer. Summarize any text given to you concisely.",
tools=[summarize_text],
include_contents="none", # No parent context
)
# This sub-agent WILL see the parent's conversation history (default)
context_aware_helper = Agent(
name="context_aware_helper_49",
model=settings.llm_model,
instructions="You are a helpful assistant that builds on prior conversation context.",
)
coordinator = Agent(
name="coordinator_49",
model=settings.llm_model,
instructions=(
"You coordinate tasks. Route summarization requests to "
"independent_summarizer_49 and general questions to context_aware_helper_49."
),
agents=[independent_summarizer, context_aware_helper],
strategy="handoff",
)
if __name__ == "__main__":
with AgentRuntime() as runtime:
result = runtime.run(
coordinator,
"Please summarize this: 'The quick brown fox jumps over the lazy dog. "
"This sentence contains every letter of the alphabet and is commonly "
"used for typography testing.'",
)
result.print_result()
# Production pattern:
# 1. Deploy once during CI/CD:
# runtime.deploy(coordinator)
# CLI alternative:
# agentspan deploy --package examples.49_include_contents
#
# 2. In a separate long-lived worker process:
# runtime.serve(coordinator)