-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcommon.py
More file actions
30 lines (23 loc) · 1 KB
/
Copy pathcommon.py
File metadata and controls
30 lines (23 loc) · 1 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
import os
from contextlib import nullcontext
from typing import Any
from pydantic_ai import Agent
from pydantic_ai.models.test import TestModel
SWARM = "team.electron.network"
# Set these to real models to run the demo live, e.g.
# ARCHITECT_MODEL=anthropic:claude-fable-5 CODER_MODEL=openai:gpt-5.5
# Unset, the demo runs offline against pydantic-ai's TestModel.
ARCHITECT_MODEL = os.getenv("ARCHITECT_MODEL")
CODER_MODEL = os.getenv("CODER_MODEL")
def make_agent(
model: str | None, instructions: str, fallback: str
) -> tuple[Agent, TestModel | None]:
if model:
return Agent(model, instructions=instructions), None
test_model = TestModel(custom_output_text=fallback)
return Agent(test_model, instructions=instructions), test_model
async def run_agent(agent: Agent, test_model: TestModel | None, prompt: str) -> Any:
context = agent.override(model=test_model) if test_model is not None else nullcontext()
with context:
result = await agent.run(prompt)
return result.output