Agentic Playbook
A practical guide for declaratively defining AI agent workflows like Infrastructure-as-Code (IaC), automating compliance, and ensuring audit trails.
1. What Is a Playbook?โ
Agentic Playbook is a framework for declaratively defining AI agent behavior, similar to Kubernetes Manifests or Terraform.
Why Is It Needed?โ
| Stage | Characteristics | Problems |
|---|---|---|
| Simple prompt | "Review this code" | Not reproducible, not auditable, unclear accountability |
| Reproducible workflow | Define steps with LangGraph | Managed as code, no approval gates |
| Auditable process | Playbook YAML | Declarative definition, GitOps deployment, automated audit logging |
- Terraform: Declare infrastructure state โ
terraform applyโ Create actual resources - Playbook: Declare agent workflow โ
playbook runโ Execute actual tasks + audit log
Core Featuresโ
- Declarative definition: Express workflows in YAML
- Approval gates: auto/manual/conditional policies
- Audit trails: Automatic Langfuse + CloudTrail integration
- GitOps deployment: Version management and rollback with ArgoCD
- Compliance tagging: SOC2, ISO27001 mapping
2. Kiro Steering vs Agentic Playbookโ
| Item | Kiro Steering/Spec | Agentic Playbook |
|---|---|---|
| Scope | Single agent behavior guide | Multi-agent workflow |
| Definition method | steering.yaml (local) | playbook.yaml (GitOps) |
| Approval gates | None | auto/manual/conditional |
| Audit logs | Local file | Langfuse + CloudTrail |
| Deployment | Manual file modification | ArgoCD automated deployment |
| Rollback | Manual recovery | Git revert auto-rollback |
| Compliance | No tagging | SOC2/ISO27001 auto-mapping |
| Application | 1 agent | N agents collaboration |
- Kiro Steering: Control single agent prompt behavior (e.g., "output JSON only", "use code blocks")
- Agentic Playbook: Workflows where multiple agents collaborate (e.g., code review โ security review โ approval)
3. Playbook YAML Specโ
Basic Structureโ
apiVersion: agenticops/v1
kind: Playbook
metadata:
name: playbook-name
compliance: [SOC2-CC7.1, ISO27001-A.14.2.1]
tags: [security, code-review]
spec:
trigger: event-name
stages:
- name: stage-1
agent: model-name
guardrails: [rule-1, rule-2]
approval: auto|manual|conditional
sla: duration
rollback:
on-failure: action
notification: [channel-1, channel-2]
Production Example: Code Review Agentโ
apiVersion: agenticops/v1
kind: Playbook
metadata:
name: code-review-agent
compliance: [SOC2-CC7.1, ISO27001-A.14.2.1]
tags: [security, code-quality, pr-automation]
description: "Automatic code review and security review on Pull Request creation"
spec:
trigger: pull-request-created
stages:
# Stage 1: Code Analysis
- name: code-analysis
agent: glm-5
guardrails:
- no-secrets-in-code
- pii-detection
- owasp-basic-check
approval: auto
timeout: 10m
output-schema: code-analysis-report.json
# Stage 2: Security Deep Review
- name: security-review
agent: glm-5
lora: security-specialist # LoRA adapter applied
rag-source: security-policies # Internal security policy RAG
guardrails:
- owasp-top-10
- cwe-top-25
approval: manual # Security team approval required
approvers:
- role: security-team
- user: security-lead@company.com
sla: 4h
notification:
on-pending: [slack-security-channel]
output-schema: security-report.json
# Stage 3: Compliance Check
- name: compliance-check
agent: glm-5
rag-source: compliance-policies # SOC2, ISO27001 document RAG
guardrails:
- gdpr-compliance
- sox-compliance
approval: conditional
conditions:
- if: security-report.risk-level >= HIGH
then: manual
- else: auto
audit-log: required # Mandatory audit log recording
output-schema: compliance-report.json
# Stage 4: Final Approval
- name: final-approval
agent: glm-5
approval: manual
approvers:
- role: tech-lead
context:
- code-analysis-report.json
- security-report.json
- compliance-report.json
sla: 2h
rollback:
on-failure: revert-to-previous
notification:
- slack-security
- email-ciso
audit:
log-to: [langfuse, cloudtrail, s3]
monitoring:
metrics:
- name: approval-latency
target: p95 < 4h
- name: false-positive-rate
target: < 5%
alerts:
- condition: approval-latency > 6h
notify: [slack-eng-ops]
- Approval SLA: Auto-escalation occurs if
sla: 4his exceeded - Audit logs: Stages with
audit-log: requiredrecord all I/O to Langfuse + CloudTrail - Rollback policy: Auto-rollback on failure, so always set approval for critical actions
4. Implementation Technology Mappingโ
How to implement each Playbook component with actual technology stack:
| Playbook Component | Existing Technology | Agentic AI Platform Layer | Notes |
|---|---|---|---|
| Workflow definition | LangGraph / CrewAI / AutoGen | L2 Orchestration | Multi-agent collaboration |
| Agent management | Kagent / A2A Protocol | L2 Gateway-Agents | Agent lifecycle |
| Guardrails | NeMo Guardrails / Guardrails AI | L2 Orchestration | Real-time safety |
| Audit logging | Langfuse + S3 | Operations | trace + generation records |
| Prompt management | Langfuse Prompts | Operations | Version control, A/B testing |
| Evaluation | RAGAS / DeepEval / LangSmith | Operations | Quality metrics |
| Deployment | ArgoCD + GitOps | Infrastructure | Kubernetes Operator pattern |
| Approval gates | PagerDuty / Slack API | Operations | Human intervention points |
| RAG sources | Milvus + Neo4j | L2 Gateway-Agents | Vector + Graph RAG |
| LoRA adapters | vLLM + HuggingFace PEFT | L1 Model Serving | Model specialization |
Technology Stack Diagramโ
5. Approval Gate Patternsโ
1. Auto Approvalโ
Proceeds immediately to next stage if guardrails pass:
- name: code-formatting
agent: glm-5
guardrails: [style-guide-check]
approval: auto
Applicable scenarios: Formatting, lint checks, simple code analysis
2. Manual Approvalโ
Designated team/role must approve:
- name: production-deployment
agent: glm-5
approval: manual
approvers:
- role: sre-team
- user: release-manager@company.com
sla: 2h
notification:
on-pending: [slack-sre, pagerduty-sre]
Applicable scenarios: Production deployment, security changes, data deletion
3. Conditional Approvalโ
Requires manual approval only under specific conditions:
- name: database-migration
agent: glm-5
approval: conditional
conditions:
- if: migration.affected-rows > 10000
then: manual
approvers: [dba-team]
- if: migration.affected-rows > 1000
then: manual
approvers: [tech-lead]
- else: auto
sla: 1h
Applicable scenarios: Risk-based approval, cost-based approval, impact scope-based approval
- Comparison operators:
>,<,>=,<=,==,!= - Logical operators:
AND,OR,NOT - Context references:
security-report.risk-level,cost-estimate.total
6. Audit Trail Implementationโ
Audit Log Architectureโ
Langfuse Integration Exampleโ
spec:
stages:
- name: security-review
agent: glm-5
audit-log: required
langfuse:
trace-id: auto # Auto-generate
tags: [security, compliance, high-risk]
metadata:
playbook: code-review-agent
compliance: [SOC2-CC7.1]
approver: ${approver.email}
timestamp: ${execution.start-time}
Audit Log Retention Policyโ
| Log Type | Retention Period | Storage | Search Method |
|---|---|---|---|
| Real-time traces | 7 days | Langfuse (PostgreSQL) | Langfuse UI |
| Short-term audit | 90 days | S3 Standard | Athena |
| Long-term archive | 7 years | S3 Glacier | Glue + Athena |
| Compliance evidence | Permanent | S3 Glacier Deep Archive | Manual restore |
- SOC2 Type II: Minimum 12-month log retention
- ISO27001: Minimum 6-month security event retention
- GDPR: Minimum 3-year personal data processing log retention
- Financial regulations (FSS): 5-year electronic financial transaction log retention (Electronic Financial Supervisory Regulation)
7. Validation Frameworkโ
Quality gates before Playbook deployment:
1. Unit Testsโ
Verify workflow logic:
import pytest
from agentic_playbook import PlaybookRunner
def test_code_review_workflow():
playbook = PlaybookRunner.from_file("code-review-agent.yaml")
# Mock PR data
pr_data = {
"files_changed": 5,
"lines_added": 200,
"risk_level": "LOW"
}
# Execute
result = playbook.run(pr_data)
# Verify
assert result.stages["code-analysis"].status == "passed"
assert result.stages["security-review"].approval_needed == False # LOW risk is auto
assert result.audit_log.compliance_tags == ["SOC2-CC7.1"]
2. RAGAS Evaluationโ
Verify AI-generated result quality:
from ragas import evaluate
from ragas.metrics import faithfulness, answer_relevancy
def test_security_review_quality():
# Actual execution
result = playbook.run_stage("security-review", test_data)
# RAGAS evaluation
scores = evaluate(
dataset=test_dataset,
metrics=[faithfulness, answer_relevancy]
)
# Threshold verification
assert scores["faithfulness"] > 0.8
assert scores["answer_relevancy"] > 0.9
3. Guardrails Testโ
Verify safety mechanism operation:
def test_guardrails_block_secrets():
malicious_code = """
AWS_SECRET_KEY = "AKIAIOSFODNN7EXAMPLE"
"""
result = playbook.run_stage("code-analysis", {"code": malicious_code})
# Verify guardrail blocked
assert result.guardrails_triggered == ["no-secrets-in-code"]
assert result.status == "blocked"