Skip to content

Refactor/split sdk python agentfield agent into mixins#453

Merged
AbirAbbas merged 9 commits intoAgent-Field:mainfrom
Luffy2208:refactor/split-sdk-python-agentfield-agent-into-mixins
Apr 15, 2026
Merged

Refactor/split sdk python agentfield agent into mixins#453
AbirAbbas merged 9 commits intoAgent-Field:mainfrom
Luffy2208:refactor/split-sdk-python-agentfield-agent-into-mixins

Conversation

@Luffy2208
Copy link
Copy Markdown
Contributor

Summary

Refactored sdk/python/agentfield/agent.py (~4500 LOC) by splitting it into multiple concern-based mixins while preserving all existing behavior and public APIs.

This change is part of the "god files" refactor epic and improves maintainability, readability, and contributor experience by organizing logically grouped functionality into separate modules.


What was moved where

agent_schema.py_AgentSchemaMixin

  • _types_to_json_schema
  • _type_to_json_schema
  • _validate_handler_input

agent_discovery.py_AgentDiscoveryMixin

  • _handle_discovery
  • _build_callback_discovery_payload
  • _apply_discovery_response

agent_serverless.py_AgentServerlessMixin

  • handle_serverless

agent_vc.py_AgentVCMixin

  • _initialize_did_system
  • _populate_execution_context_with_did
  • _agent_vc_default
  • _set_reasoner_vc_override
  • _set_skill_vc_override
  • _effective_component_vc_setting
  • _should_generate_vc
  • _build_agent_metadata
  • _build_vc_metadata
  • _generate_vc_async

agent_pause.py

  • _PauseManager class (moved as-is)

Agent Composition

The Agent class now composes these via mixins:

class Agent(
    FastAPI,
    _AgentSchemaMixin,
    _AgentDiscoveryMixin,
    _AgentVCMixin,
    _AgentServerlessMixin,
):
    ...

Testing

  • ./scripts/test-all.sh
  • Additional verification:
    uv run pytest sdk/python/tests/
    All tests passed ✅

Test Changes

No existing tests were modified.
Added monkeypatch overrides in test/helper.py:

monkeypatch.setattr("agentfield.agent_vc.DIDManager", _FakeDIDManager)
monkeypatch.setattr("agentfield.agent_vc.VCGenerator", _FakeVCGenerator)

Checklist

  • I updated documentation where applicable.
  • I added or updated tests (or none were needed).
  • I updated CHANGELOG.md (or this change does not warrant a changelog entry).

Related Issues

Fixes #411

@Luffy2208 Luffy2208 requested review from a team and AbirAbbas as code owners April 14, 2026 10:39
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 14, 2026

Performance

SDK Memory Δ Latency Δ Tests Status
Python 7.9 KB -13% 0.33 µs -6%

✓ No regressions detected

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 14, 2026

📊 Coverage gate

Thresholds from .coverage-gate.toml: per-surface ≥ 86%, aggregate ≥ 88%, max per-surface regression ≤ 1.0 pp, max aggregate regression ≤ 0.50 pp.

Surface Current Baseline Δ
control-plane 87.20% 87.30% ↓ -0.10 pp 🟡
sdk-go 90.70% 90.70% → +0.00 pp 🟢
sdk-python 93.63% 93.63% ↑ +0.00 pp 🟢
sdk-typescript 92.56% 92.56% → +0.00 pp 🟢
web-ui 90.02% 90.01% ↑ +0.01 pp 🟢
aggregate 88.98% 89.01% ↓ -0.03 pp 🟡

✅ Gate passed

No surface regressed past the allowed threshold and the aggregate stayed above the floor.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 14, 2026

📐 Patch coverage gate

Threshold: 80% on lines this PR touches vs origin/main (from .coverage-gate.toml:thresholds.min_patch).

Surface Touched lines Patch coverage Status
control-plane 0 ➖ no changes
sdk-go 0 ➖ no changes
sdk-python 0 ➖ no changes
sdk-typescript 0 ➖ no changes
web-ui 0 ➖ no changes

✅ Patch gate passed

Every surface whose lines were touched by this PR has patch coverage at or above the threshold.

@AbirAbbas
Copy link
Copy Markdown
Contributor

CI is failing — ruff catches an unused import asyncio in agent_vc.py:1. Remove that and you should be green.

Comment thread sdk/python/agentfield/agent_vc.py Outdated
@AbirAbbas AbirAbbas enabled auto-merge April 15, 2026 14:41
@AbirAbbas AbirAbbas added this pull request to the merge queue Apr 15, 2026
Merged via the queue into Agent-Field:main with commit 4335368 Apr 15, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor] Split sdk/python/agentfield/agent.py (4503 LOC) into mixins

3 participants