From 59bea09248420cc283f10e24d884cdfa854064b3 Mon Sep 17 00:00:00 2001 From: a2a-cloud Date: Mon, 13 Jul 2026 03:07:24 +0000 Subject: [PATCH] a2a-source-edit: write agent.py --- agent.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/agent.py b/agent.py index 7527d20..0b82cd6 100644 --- a/agent.py +++ b/agent.py @@ -263,6 +263,68 @@ class AgentComplianceAuditorConfig(StrictModel): default_allowed_namespaces: list[str] = Field(default_factory=list, max_length=50) +def _tool_schema(kind: str) -> dict[str, Any]: + request_schema: dict[str, Any] = { + "type": "object", + "additionalProperties": False, + "properties": { + "target": { + "type": "object", + "additionalProperties": False, + "properties": { + "agent_name": {"type": "string", "minLength": 1, "maxLength": 128, "pattern": "^[a-z0-9][a-z0-9-]{0,127}$"}, + "agent_url": {"type": ["string", "null"], "format": "uri"}, + "repository": {"type": ["string", "null"], "maxLength": 256}, + "namespace": {"type": ["string", "null"], "maxLength": 128}, + "deployment": {"type": ["string", "null"], "maxLength": 128}, + }, + "required": ["agent_name"], + }, + "options": { + "type": "object", + "additionalProperties": False, + "properties": { + "audit_id": {"type": ["string", "null"], "maxLength": 80, "pattern": "^[A-Za-z0-9_.-]+$"}, + "max_files": {"type": "integer", "minimum": 0, "maximum": MAX_FILES_PER_AUDIT, "default": 40}, + "probe_mode": {"type": "string", "enum": ["none", "health_only", "synthetic"], "default": "health_only"}, + "include_repository": {"type": "boolean", "default": True}, + "include_runtime": {"type": "boolean", "default": True}, + "include_remediation": {"type": "boolean", "default": True}, + "allowed_hosts": {"type": "array", "items": {"type": "string"}, "maxItems": 20, "default": []}, + "allowed_namespaces": {"type": "array", "items": {"type": "string"}, "maxItems": 20, "default": []}, + }, + }, + }, + "required": ["target"], + } + if kind in {"configuration", "runtime", "risk"}: + request_schema["properties"]["inventory"] = {"type": ["object", "null"], "additionalProperties": True} + finding_schema = { + "type": "object", + "additionalProperties": False, + "properties": { + "id": {"type": "string"}, + "control_id": {"type": "string"}, + "title": {"type": "string"}, + "severity": {"type": "string", "enum": ["critical", "high", "medium", "low", "info"]}, + "confidence": {"type": "string", "enum": ["high", "medium", "low"]}, + "status": {"type": "string", "enum": ["open", "passed", "unknown", "not_tested"], "default": "open"}, + "evidence_refs": {"type": "array", "items": {"type": "string"}, "maxItems": 20, "default": []}, + "impact": {"type": "string"}, + "remediation": {"type": "string"}, + "verification_procedure": {"type": "string"}, + }, + "required": ["id", "control_id", "title", "severity", "confidence", "impact", "remediation", "verification_procedure"], + } + if kind == "risk": + request_schema["properties"]["configuration_findings"] = {"type": "array", "items": finding_schema, "maxItems": MAX_FINDINGS, "default": []} + request_schema["properties"]["runtime_findings"] = {"type": "array", "items": finding_schema, "maxItems": MAX_FINDINGS, "default": []} + if kind == "remediation": + request_schema["properties"]["findings"] = {"type": "array", "items": finding_schema, "maxItems": MAX_FINDINGS, "default": []} + request_schema["properties"]["risk_summary"] = {"type": ["object", "null"], "additionalProperties": True} + return {"type": "object", "additionalProperties": False, "properties": {"request": request_schema}, "required": ["request"]} + + class AgentComplianceAuditor(A2AAgent[AgentComplianceAuditorConfig, NoAuth]): name = "agent-compliance-auditor" description = (