Skip to content

Migrating GymCoach to AgentSpec

This guide shows how to capture an existing agent's configuration in an agent.yaml manifest. GymCoach is an AI fitness coaching assistant with 10 tools, Redis memory, Postgres, Langfuse, and deepeval.

Analysis: What GymCoach Has

ComponentCurrent locationAgentSpec field
ModelGROQ_API_KEY + groq clientspec.model.provider: groq
FallbackAZURE_OPENAI_API_KEYspec.model.fallback
System promptbackend/app/prompts/system_prompt.txtspec.prompts.system: $file:prompts/system_prompt.txt
Tools (10)tool_implementations.pyspec.tools[]
Short-term memoryRedis (Upstash) REDIS_URLspec.memory.shortTerm.backend: redis
Long-term memoryPostgres DATABASE_URLspec.memory.longTerm
Sub-agentsobserver.yaml, reflector.yamlspec.subagents[]
APIFastAPI on port 8000spec.api.type: rest
Evaluationdeepevalspec.evaluation.framework: deepeval
ObservabilityLangfusespec.observability.tracing.backend: langfuse
Guardrailsguardrails.py topic filterspec.guardrails.input[].type: topic-filter

The Manifest

The complete manifest is at examples/gymcoach/agent.yaml.

Key sections:

yaml
spec:
  model:
    provider: groq
    id: llama-3.3-70b-versatile
    apiKey: $env:GROQ_API_KEY
    fallback:
      provider: azure
      id: gpt-4
      apiKey: $env:AZURE_OPENAI_API_KEY
      triggerOn: [rate_limit, timeout, error_5xx]
      maxRetries: 2
    costControls:
      maxMonthlyUSD: 200
      alertAtUSD: 150

  memory:
    shortTerm:
      backend: redis
      maxTurns: 20
      maxTokens: 8000
      ttlSeconds: 3600
      connection: $env:REDIS_URL
    longTerm:
      backend: postgres
      connectionString: $env:DATABASE_URL
      ttlDays: 90
    hygiene:
      piiScrubFields: [name, email, date_of_birth, medical_conditions]
      auditLog: true

Step 1: Validate

bash
agentspec validate examples/gymcoach/agent.yaml

Step 2: Health Check (in GymCoach repo, with env vars set)

bash
cd /path/to/gymcoach
agentspec health agent.yaml

This verifies:

  • GROQ_API_KEY, DATABASE_URL, REDIS_URL are set
  • All $file: references exist (system prompt, eval datasets)
  • Groq API is reachable
  • Redis is reachable
  • Postgres is reachable

Step 3: Audit

bash
agentspec audit agent.yaml

GymCoach's full manifest scores ~85/100 (grade B) because:

  • ✓ Fallback model declared (MODEL-01)
  • ✓ Cost controls set (MODEL-03)
  • ✓ PII scrub configured (SEC-LLM-06, MEM-01)
  • ✓ Guardrails configured (SEC-LLM-01, SEC-LLM-02)
  • ✓ Evaluation + CI gate (SEC-LLM-09, EVAL-02)
  • ✗ API keys use $env: instead of $secret: (SEC-LLM-10)
  • ✗ No vector store namespace (MEM-04)

Step 4: Generate LangGraph Code

bash
export ANTHROPIC_API_KEY=your-api-key-here
agentspec generate agent.yaml --framework langgraph --output ./generated/

This produces a LangGraph version of GymCoach, preserving all tools, memory, and guardrail structure.

Step 5: Add to AGENTS.md

markdown
## Agent Manifest

This project uses [AgentSpec](https://agentspec.io) for agent configuration.
See [agent.yaml](./agent.yaml) for the full manifest.

```bash
agentspec health   # Check runtime dependencies
agentspec audit    # Compliance report (OWASP LLM Top 10)

Released under the Apache 2.0 License.