Python: [BREAKING] added SerializationMixin and applied to contents, agents, chat client… (#1012)

* added SerializationMixin and applied to contents, agents, chat clients, removed AFBaseModel

* fix annotations type

* mypy fixes

* fix tests

* fix serializable subvalues and added large docstring

* updated indents in code block

* fixed exported urls
This commit is contained in:
Eduard van Valkenburg
2025-09-30 21:53:46 +02:00
committed by GitHub
Unverified
parent 3eb26632ce
commit 54ad135914
84 changed files with 2302 additions and 1957 deletions
+1 -1
View File
@@ -51,7 +51,7 @@ async def math_agent(task: TaskType, llm: LLM) -> float:
MCPStdioTool(name="calculator", command="uvx", args=["mcp-server-calculator"]) as mcp_server,
ChatAgent(
chat_client=OpenAIChatClient(
ai_model_id=llm.model,
model_id=llm.model,
api_key="your-api-key",
base_url=llm.endpoint,
),
@@ -168,7 +168,7 @@ async def math_agent(task: MathProblem, llm: LLM) -> float:
MCPStdioTool(name="calculator", command="uvx", args=["mcp-server-calculator"]) as mcp_server,
ChatAgent(
chat_client=OpenAIChatClient(
ai_model_id=llm.model, # This is the model being trained
model_id=llm.model, # This is the model being trained
api_key=os.getenv("OPENAI_API_KEY") or "dummy", # Can be dummy when connecting to training LLM
base_url=llm.endpoint, # vLLM server endpoint provided by agent-lightning
),
@@ -103,14 +103,14 @@ class Tau2Agent(LitAgent):
assistant_chat_client = OpenAIChatClient(
base_url=llm.endpoint, # vLLM endpoint for the model being trained
api_key=openai_api_key,
ai_model_id=llm.model, # Model ID being trained
model_id=llm.model, # Model ID being trained
)
# User simulator: uses a fixed, capable model for consistent simulation
user_simulator_chat_client = OpenAIChatClient(
base_url=openai_base_url, # External API endpoint
api_key=openai_api_key,
ai_model_id="gpt-4.1", # Fixed model for user simulator
model_id="gpt-4.1", # Fixed model for user simulator
)
try:
@@ -18,10 +18,6 @@ from openai.types.chat import ChatCompletion, ChatCompletionMessage
from openai.types.chat.chat_completion import Choice
def test_import():
"""Test that the module can be imported."""
@pytest.fixture
def workflow_two_agents():
"""Test a workflow with two OpenAI chat agents where first agent's result passes to second agent."""
@@ -111,14 +107,12 @@ def workflow_two_agents():
yield workflow
@pytest.mark.asyncio
async def test_openai_workflow_two_agents(workflow_two_agents):
events = await workflow_two_agents.run("Please analyze the quarterly sales data")
assert "Based on the analysis 'Analyzed data shows trend upward', I recommend investing" in events.get_outputs()
@pytest.mark.asyncio
async def test_observability(workflow_two_agents):
r"""Expected trace tree:
+21
View File
@@ -54,6 +54,27 @@ math = [
"sympy>=1.13.0",
]
[dependency-groups]
dev = [
"uv>=0.8.2,<0.9.0",
"pre-commit >= 3.7",
"ruff>=0.11.8",
"pytest>=8.4.1",
"pytest-asyncio>=1.0.0",
"pytest-cov>=6.2.1",
"pytest-env>=1.1.5",
"pytest-xdist[psutil]>=3.8.0",
"pytest-timeout>=2.3.1",
"pytest-retry>=1",
"mypy>=1.16.1",
"pyright>=1.1.402",
#tasks
"poethepoet>=0.36.0",
"rich",
"tomli",
"tomli-w",
]
[project.scripts]
gaia_viewer = "agent_framework_lab_gaia:viewer_main"
lightning = "agent_framework_lab_lightning:main"
+2 -2
View File
@@ -61,12 +61,12 @@ async def run_single_task():
assistant_client = OpenAIChatClient(
base_url="https://api.openai.com/v1",
api_key="your-api-key",
ai_model_id="gpt-4o"
model_id="gpt-4o"
)
user_client = OpenAIChatClient(
base_url="https://api.openai.com/v1",
api_key="your-api-key",
ai_model_id="gpt-4o-mini"
model_id="gpt-4o-mini"
)
# Get a task and run it
@@ -96,14 +96,14 @@ async def run_benchmark(assistant_model: str, user_model: str, debug_task_id: st
assistant_chat_client = OpenAIChatClient(
base_url=openai_base_url,
api_key=openai_api_key,
ai_model_id=assistant_model,
model_id=assistant_model,
)
# User simulator: simulates realistic customer behavior and requests
user_simulator_chat_client = OpenAIChatClient(
base_url=openai_base_url,
api_key=openai_api_key,
ai_model_id=user_model,
model_id=user_model,
)
# STEP 4: Filter task set for debug mode
@@ -133,8 +133,8 @@ async def run_benchmark(assistant_model: str, user_model: str, debug_task_id: st
# Initialize result structure for this task
result: dict[str, Any] = {
"config": {
"assistant": assistant_chat_client.ai_model_id,
"user": user_simulator_chat_client.ai_model_id,
"assistant": assistant_chat_client.model_id,
"user": user_simulator_chat_client.model_id,
},
"task": task,
}
@@ -183,8 +183,8 @@ async def run_benchmark(assistant_model: str, user_model: str, debug_task_id: st
# Initialize result structure for this task
result: dict[str, Any] = {
"config": {
"assistant": assistant_chat_client.ai_model_id,
"user": user_simulator_chat_client.ai_model_id,
"assistant": assistant_chat_client.model_id,
"user": user_simulator_chat_client.model_id,
},
"task": task,
}