Sanitize generated pricing fields
All checks were successful
build / build (push) Successful in 4s

This commit is contained in:
robert
2026-06-02 14:19:13 -03:00
parent c9818bda97
commit 9a90add738
5 changed files with 183 additions and 5 deletions

View File

@@ -12,7 +12,7 @@ from agent_builder.builder import (
_with_builder_skills,
)
from agent_builder.config import Settings
from agent_builder.tools import A2A_PACK_MIN_VERSION
from agent_builder.tools import A2A_PACK_MIN_VERSION, _strip_unsupported_pricing_fields
from deepagents.backends import StateBackend
from agent import _build_failure_error
@@ -68,6 +68,48 @@ class BuilderPromptTests(unittest.TestCase):
self.assertIn("caller_pays_llm=False", files["a2apack-agent-authoring/SKILL.md"])
self.assertIn("ctx.llm.api_key", files["agent-quality-review/SKILL.md"])
def test_prompt_rejects_platform_derived_pricing_fields(self) -> None:
self.assertIn("runtime.pricing.compute", SYSTEM_PROMPT)
self.assertIn("runtime.pricing.total_usd", SYSTEM_PROMPT)
self.assertIn("price_per_call_usd", SYSTEM_PROMPT)
files = _builder_skill_files()
for path in (
"a2apack-agent-authoring/SKILL.md",
"agent-quality-review/SKILL.md",
):
self.assertIn("runtime.pricing.compute", files[path])
self.assertIn("runtime.pricing.total_usd", files[path])
self.assertIn("compute=", files[path])
self.assertIn("total_usd=", files[path])
def test_pricing_sanitizer_removes_derived_agent_card_fields(self) -> None:
source = '''
from a2a_pack import Pricing
pricing = Pricing(
price_per_call_usd=0.05,
compute={
"cpu_usd": 0.000833,
"memory_usd": 0.00018,
},
total_usd=0.10125,
caller_pays_llm=False,
notes="caller gets the real billing projection from the platform",
)
inline = Pricing(price_per_call_usd=0.01, compute={"runtime_seconds": 600}, total_usd=0.02, caller_pays_llm=False)
'''
sanitized, removed = _strip_unsupported_pricing_fields(source)
self.assertEqual(set(removed), {"compute", "total_usd"})
self.assertIn("price_per_call_usd=0.05", sanitized)
self.assertIn("caller_pays_llm=False", sanitized)
self.assertNotIn("compute=", sanitized)
self.assertNotIn("total_usd=", sanitized)
compile(sanitized, "agent.py", "exec")
def test_prompt_requires_resource_mirror_for_heavy_agents(self) -> None:
self.assertIn("declare resources in BOTH places", SYSTEM_PROMPT)
self.assertIn("resources = Resources", SYSTEM_PROMPT)