Skip to content

Commit fc1970c

Browse files
authored
Merge pull request #190 from UiPath/samples/agent-framework-orchestrations
Add structured-output, magentic, and sequential samples
2 parents 152ffcd + 02ef726 commit fc1970c

9 files changed

Lines changed: 319 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Magentic
2+
3+
A multi-agent orchestration based on the Magentic-One pattern. A dedicated manager dynamically coordinates specialized agents (researcher and analyst), selecting who acts next based on task progress and context.
4+
5+
## Agent Graph
6+
7+
```mermaid
8+
flowchart TB
9+
__start__(__start__)
10+
magentic_workflow(magentic_workflow)
11+
__end__(__end__)
12+
__start__ --> |input|magentic_workflow
13+
magentic_workflow --> |output|__end__
14+
```
15+
16+
Internally, the magentic orchestration manages:
17+
- **researcher** — finds facts via Wikipedia
18+
- **analyst** — analyzes data and draws conclusions
19+
- **magentic_manager** — plans, selects the next agent, and tracks progress
20+
21+
The manager dynamically selects which agent should act next based on the evolving context.
22+
23+
## Prerequisites
24+
25+
Authenticate with UiPath to configure your `.env` file:
26+
27+
```bash
28+
uipath auth
29+
```
30+
31+
## Run
32+
33+
```
34+
uipath run agent '{"messages": [{"contentParts": [{"data": {"inline": "Compare the environmental impacts of solar and wind energy production"}}], "role": "user"}]}'
35+
```
36+
37+
## Debug
38+
39+
```
40+
uipath dev web
41+
```
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import httpx
2+
from agent_framework.orchestrations import MagenticBuilder
3+
4+
from uipath_agent_framework.chat import UiPathOpenAIChatClient
5+
6+
7+
def search_wikipedia(query: str) -> str:
8+
"""Search Wikipedia for a topic and return a summary.
9+
10+
Args:
11+
query: The search query, e.g. "Python programming language"
12+
13+
Returns:
14+
A summary of the Wikipedia article, or an error message.
15+
"""
16+
try:
17+
resp = httpx.get(
18+
"https://en.wikipedia.org/api/rest_v1/page/summary/"
19+
+ query.replace(" ", "_"),
20+
headers={"User-Agent": "UiPathMagentic/1.0"},
21+
timeout=10,
22+
follow_redirects=True,
23+
)
24+
resp.raise_for_status()
25+
data = resp.json()
26+
return data.get("extract", "No summary available.")
27+
except Exception as e:
28+
return f"Wikipedia search failed for '{query}': {e}"
29+
30+
31+
client = UiPathOpenAIChatClient(model="gpt-5-mini-2025-08-07")
32+
33+
researcher = client.as_agent(
34+
name="researcher",
35+
description="Specialist in research and information gathering using Wikipedia.",
36+
instructions=(
37+
"You are a Researcher. Use the search_wikipedia tool to find factual "
38+
"information. Provide concise, well-sourced responses without additional "
39+
"computation or quantitative analysis."
40+
),
41+
tools=[search_wikipedia],
42+
)
43+
44+
analyst = client.as_agent(
45+
name="analyst",
46+
description="Specialist in analyzing data and drawing conclusions.",
47+
instructions=(
48+
"You are an Analyst. Analyze the information gathered by other agents. "
49+
"Draw conclusions, identify patterns, and provide actionable insights. "
50+
"Be precise and support your analysis with evidence from the discussion."
51+
),
52+
)
53+
54+
manager = client.as_agent(
55+
name="magentic_manager",
56+
description="Orchestrator that coordinates the research and analysis workflow.",
57+
instructions=(
58+
"You coordinate a team of researcher and analyst to complete complex "
59+
"tasks efficiently. Break down problems, delegate subtasks, and "
60+
"synthesize results into a comprehensive final answer."
61+
),
62+
)
63+
64+
workflow = MagenticBuilder(
65+
participants=[researcher, analyst],
66+
manager_agent=manager,
67+
max_round_count=6,
68+
max_stall_count=2,
69+
max_reset_count=1,
70+
).build()
71+
72+
agent = workflow.as_agent(name="magentic_workflow")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[project]
2+
name = "magentic"
3+
version = "0.0.1"
4+
description = "Magentic: dynamic multi-agent orchestration with a planning manager"
5+
authors = [{ name = "John Doe" }]
6+
readme = "README.md"
7+
requires-python = ">=3.11"
8+
dependencies = [
9+
"uipath",
10+
"uipath-agent-framework",
11+
"agent-framework-core>=1.0.0rc1",
12+
"agent-framework-orchestrations>=1.0.0b260219",
13+
]
14+
15+
[dependency-groups]
16+
dev = [
17+
"uipath-dev",
18+
]
19+
20+
[tool.uv]
21+
prerelease = "allow"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Sequential
2+
3+
A sequential pipeline where agents process a task one after another. A writer creates marketing copy, a reviewer provides feedback, and an editor produces the polished final version.
4+
5+
## Agent Graph
6+
7+
```mermaid
8+
flowchart TB
9+
__start__(__start__)
10+
sequential_workflow(sequential_workflow)
11+
__end__(__end__)
12+
__start__ --> |input|sequential_workflow
13+
sequential_workflow --> |output|__end__
14+
```
15+
16+
Internally, the sequential orchestration chains:
17+
- **writer** — creates an initial marketing paragraph
18+
- **reviewer** — provides constructive feedback on the draft
19+
- **editor** — incorporates feedback and produces the final polished version
20+
21+
Each agent sees the full conversation history from previous agents.
22+
23+
## Prerequisites
24+
25+
Authenticate with UiPath to configure your `.env` file:
26+
27+
```bash
28+
uipath auth
29+
```
30+
31+
## Run
32+
33+
```
34+
uipath run agent '{"messages": [{"contentParts": [{"data": {"inline": "Write a tagline for a budget-friendly eBike"}}], "role": "user"}]}'
35+
```
36+
37+
## Debug
38+
39+
```
40+
uipath dev web
41+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from agent_framework.orchestrations import SequentialBuilder
2+
3+
from uipath_agent_framework.chat import UiPathOpenAIChatClient
4+
5+
client = UiPathOpenAIChatClient(model="gpt-5-mini-2025-08-07")
6+
7+
writer = client.as_agent(
8+
name="writer",
9+
description="Creates concise, engaging marketing copy.",
10+
instructions=(
11+
"You are a concise copywriter. Provide a single, punchy marketing "
12+
"paragraph based on the prompt. Focus on clarity and impact."
13+
),
14+
)
15+
16+
reviewer = client.as_agent(
17+
name="reviewer",
18+
description="Reviews and provides constructive feedback on content.",
19+
instructions=(
20+
"You are a thoughtful reviewer. Give brief, constructive feedback "
21+
"on the previous assistant message. Highlight strengths and suggest "
22+
"one specific improvement."
23+
),
24+
)
25+
26+
editor = client.as_agent(
27+
name="editor",
28+
description="Polishes content based on feedback into a final version.",
29+
instructions=(
30+
"You are a skilled editor. Based on the original content and the "
31+
"reviewer's feedback, produce a polished final version. Incorporate "
32+
"the suggested improvements while maintaining the original tone."
33+
),
34+
)
35+
36+
workflow = SequentialBuilder(
37+
participants=[writer, reviewer, editor],
38+
).build()
39+
40+
agent = workflow.as_agent(name="sequential_workflow")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[project]
2+
name = "sequential"
3+
version = "0.0.1"
4+
description = "Sequential: agents process a task in a pipeline, each building on the previous output"
5+
authors = [{ name = "John Doe" }]
6+
readme = "README.md"
7+
requires-python = ">=3.11"
8+
dependencies = [
9+
"uipath",
10+
"uipath-agent-framework",
11+
"agent-framework-core>=1.0.0rc1",
12+
"agent-framework-orchestrations>=1.0.0b260219",
13+
]
14+
15+
[dependency-groups]
16+
dev = [
17+
"uipath-dev",
18+
]
19+
20+
[tool.uv]
21+
prerelease = "allow"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Structured Output
2+
3+
A simple workflow agent that returns structured data using a Pydantic model. The agent extracts city information (name, country, description, population, and notable features) and returns it in a well-defined JSON schema.
4+
5+
## Agent Graph
6+
7+
```mermaid
8+
flowchart TB
9+
__start__(__start__)
10+
city_agent(city_agent)
11+
__end__(__end__)
12+
__start__ --> |input|city_agent
13+
city_agent --> |output|__end__
14+
```
15+
16+
## Prerequisites
17+
18+
Authenticate with UiPath to configure your `.env` file:
19+
20+
```bash
21+
uipath auth
22+
```
23+
24+
## Run
25+
26+
```
27+
uipath run agent '{"messages": [{"contentParts": [{"data": {"inline": "Tell me about Tokyo"}}], "role": "user"}]}'
28+
```
29+
30+
## Debug
31+
32+
```
33+
uipath dev web
34+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from agent_framework import WorkflowBuilder
2+
from pydantic import BaseModel
3+
4+
from uipath_agent_framework.chat import UiPathOpenAIChatClient
5+
6+
7+
class CityInfo(BaseModel):
8+
"""Structured output for city information."""
9+
10+
city: str
11+
country: str
12+
description: str
13+
population_estimate: str
14+
famous_for: list[str]
15+
16+
17+
client = UiPathOpenAIChatClient(model="gpt-5-mini-2025-08-07")
18+
city_agent = client.as_agent(
19+
name="city_agent",
20+
instructions=(
21+
"You are a helpful agent that describes cities in a structured format. "
22+
"Given a city name, provide the city name, country, a brief description, "
23+
"an estimated population, and a list of things the city is famous for."
24+
),
25+
response_format=CityInfo,
26+
)
27+
28+
workflow = WorkflowBuilder(start_executor=city_agent).build()
29+
agent = workflow.as_agent(name="structured_output_workflow")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[project]
2+
name = "structured-output"
3+
version = "0.0.1"
4+
description = "Structured output: agent returns data in a well-defined Pydantic schema"
5+
authors = [{ name = "John Doe" }]
6+
readme = "README.md"
7+
requires-python = ">=3.11"
8+
dependencies = [
9+
"uipath",
10+
"uipath-agent-framework",
11+
"agent-framework-core>=1.0.0rc1",
12+
]
13+
14+
[dependency-groups]
15+
dev = [
16+
"uipath-dev",
17+
]
18+
19+
[tool.uv]
20+
prerelease = "allow"

0 commit comments

Comments
 (0)