Shared data models for Agent Control server and SDK
Project description
Agent Control Models
Shared data models for Agent Control server and SDK. This package contains all the Pydantic models used for API requests, responses, and data validation.
Why Shared Models?
Having a separate models package provides several benefits:
- Single Source of Truth: Models are defined once and used everywhere
- Type Safety: Ensures server and SDK use identical data structures
- Versioning: Models can be versioned independently
- Easier Maintenance: Changes propagate automatically to both server and SDK
- Clear Contract: API contract is explicitly defined
Common Patterns in Popular Python Packages
This design follows patterns used by popular packages:
1. Shared Models (Our Approach)
- Google APIs (
google-api-core): Separate proto/model definitions - Stripe (
stripe-python): Models package shared across components - PySpark: Shared types and schemas
2. JSON/Pydantic Hybrid
- FastAPI: Pydantic models with JSON serialization
- Anthropic SDK: Pydantic models with
.to_dict()and.from_dict() - OpenAI SDK: Typed models with JSON compatibility
Installation
This package is typically installed as a dependency:
# Server depends on it
cd server
uv add agent-control-models
# SDK depends on it
cd sdk
uv add agent-control-models
Usage
Agent Models
from agent_control_models import Agent, Step
# Create an agent
agent = Agent(
agent_name="Customer Support Bot",
agent_name="550e8400-e29b-41d4-a716-446655440000",
agent_description="Handles customer inquiries",
agent_version="1.0.0"
)
# Create a step
step = Step(
type="llm_inference",
name="chat",
input="Hello, how can I help?",
output="I'm here to assist you!"
)
Control Models
from agent_control_models import ControlDefinition, ControlScope, ControlAction
# Define a control
control = ControlDefinition(
name="block-toxic-input",
description="Block toxic user messages",
enabled=True,
execution="server",
scope=ControlScope(
step_types=["llm_inference"],
stages=["pre"]
),
action=ControlAction(decision="deny")
)
Evaluation Models
from agent_control_models import EvaluationRequest, EvaluationResponse
# Create evaluation request
request = EvaluationRequest(
agent_name="agent-uuid-here",
step=Step(
type="llm_inference",
name="chat",
input="User message"
),
stage="pre"
)
# Evaluation response
response = EvaluationResponse(
allowed=True,
violated_controls=[]
)
Models
Core Models
BaseModel
Base class for all models with common utilities:
model_dump(): Convert to Python dictionary (Pydantic v2)model_dump_json(): Convert to JSON string (Pydantic v2)model_validate(): Create from dictionary (Pydantic v2)
Configuration:
- Accepts both snake_case and camelCase fields
- Validates on assignment
- JSON-compatible serialization
Agent
Agent metadata and configuration.
Fields:
agent_name(str): Human-readable agent nameagent_name(UUID): Unique identifieragent_description(Optional[str]): Agent descriptionagent_version(Optional[str]): Agent versiontools(Optional[List[str]]): List of available toolsmetadata(Optional[Dict]): Additional metadata
Step
Represents a single step in agent execution.
Fields:
type(str): Step type (e.g., "llm_inference", "tool")name(str): Step nameinput(Optional[Any]): Step input dataoutput(Optional[Any]): Step output datacontext(Optional[Dict]): Additional context
ControlDefinition
Complete control specification.
Fields:
name(str): Control namedescription(Optional[str]): Control descriptionenabled(bool): Whether control is activeexecution(str): Execution mode ("server" or "local")scope(ControlScope): When to apply the controlselector(ControlSelector): What data to evaluateevaluator(EvaluatorSpec): How to evaluateaction(ControlAction): What to do on match
EvaluationRequest
Request for evaluating controls.
Fields:
agent_name(str): Agent identifierstep(Step): Step to evaluatestage(str): Evaluation stage ("pre" or "post")
EvaluationResponse
Response from control evaluation.
Fields:
allowed(bool): Whether the step is allowedviolated_controls(List[str]): Names of violated controlsevaluation_results(Optional[List]): Detailed evaluation results
HealthResponse
Health check response.
Fields:
status(str): Health status ("healthy")version(str): Server version
Design Patterns
1. Pydantic v2
All models use Pydantic v2 for validation and serialization:
from agent_control_models import Agent
# Create with validation
agent = Agent(
agent_name="My Agent",
agent_name="550e8400-e29b-41d4-a716-446655440000"
)
# Serialize to dict
agent_dict = agent.model_dump()
# Serialize to JSON
agent_json = agent.model_dump_json()
# Deserialize from dict
agent_copy = Agent.model_validate(agent_dict)
2. Type Safety
Models provide strong typing throughout the stack:
from agent_control_models import Step, EvaluationRequest
# Type-safe step creation
step = Step(
type="llm_inference",
name="chat",
input="Hello"
)
# Type-safe evaluation request
request = EvaluationRequest(
agent_name="uuid-here",
step=step,
stage="pre"
)
3. Extensibility
Models support additional metadata for extensibility:
from agent_control_models import Agent
# Add custom metadata
agent = Agent(
agent_name="Support Bot",
agent_name="550e8400-e29b-41d4-a716-446655440000",
metadata={
"team": "customer-success",
"environment": "production",
"custom_field": "value"
}
)
Development
Adding New Models
- Create a new file in
src/agent_control_models/ - Define models extending
BaseModel - Export in
__init__.py - Update both server and SDK to use the new models
Example:
# src/agent_control_models/auth.py
from .base import BaseModel
class AuthRequest(BaseModel):
api_key: str
# src/agent_control_models/__init__.py
from .auth import AuthRequest
__all__ = [..., "AuthRequest"]
Testing
cd models
uv run pytest
Best Practices
- Always extend BaseModel: Get free JSON/dict conversion
- Use Field for validation: Add constraints and descriptions
- Keep models simple: No business logic, just data
- Version carefully: Model changes affect both server and SDK
- Document fields: Use Field's
descriptionparameter - Use Optional appropriately: Mark optional fields clearly
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agent_control_models-6.6.2.tar.gz.
File metadata
- Download URL: agent_control_models-6.6.2.tar.gz
- Upload date:
- Size: 20.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5afd49bed40e74393041b249193a9c0673feed699b5cc6d44817fe433822438f
|
|
| MD5 |
fde79f521a8a9b3664422a44ddf5a5f0
|
|
| BLAKE2b-256 |
1bc318537675ca572747f0b098b4e67fd023bc399e1ce35a75df5b64f3c04165
|
File details
Details for the file agent_control_models-6.6.2-py3-none-any.whl.
File metadata
- Download URL: agent_control_models-6.6.2-py3-none-any.whl
- Upload date:
- Size: 25.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
775c732b7890f742efb90cd34a2620bc75347390abd5b61096c29ef5a57d54c3
|
|
| MD5 |
27fcdc3f86b026accc875e32d71c8886
|
|
| BLAKE2b-256 |
a9f7a6937ada0be63dce7f253c251e9610caa5afe8a69257804f8bf639aa7d8e
|