How lark-ai-lab/specagent works
SpecAgent is an OpenAI-compatible gateway for trajectory-level speculation: an agent sends requests through the gateway, the Weak model drafts steps, and the Strong model reviews a candidate prefix before the gateway releases accepted work or repairs a rejected step. The protocol modules provide context shaping, action gating, evidence handling, verdict parsing, and session state; separate resource modules estimate inference cost. The README also documents four benchmark integrations. Edges reflect the README and source-index references; benchmark internals and unsampled call details are not inferred.
Main entry points: gateway.py Session gateway · server.py HTTP endpoint · resource_estimate.py Resource estimates · accounting.py Token accounting
Components 27
Gateway runtime
- HTTP endpoint
src/specagent/server.py - Session gateway
src/specagent/runtime/gateway.py - Backend auth
src/specagent/http_auth.py
Review protocol
- Context views
src/specagent/protocol/context.py - Action gating
src/specagent/protocol/side_effects.py - Request evidence
src/specagent/protocol/evidence.py - Payload pruning
src/specagent/protocol/evidence_review.py - Verdict parser
src/specagent/protocol/verifier.py - Repair note
src/specagent/runtime/review_note.py - Prefix state
src/specagent/protocol/state.py - Protocol records
src/specagent/protocol/types.py
Resource estimates
- Token accounting
src/specagent/protocol/accounting.py - Estimator labels
src/specagent/protocol/estimator_ids.py - FLOPs estimator
src/specagent/protocol/flops.py - HBM estimator
src/specagent/protocol/hbm.py - Prefix reuse
src/specagent/protocol/prefix_reuse.py - Cache report
src/specagent/protocol/cache_report.py - Paper settings
src/specagent/protocol/paper.py - Resource estimates
src/specagent/protocol/resource_estimate.py
Benchmark integrations
- τ²-Bench adapter
benchmarks/tau2 - AutomationBench adapter
benchmarks/automationbench - VitaBench adapter
benchmarks/vitabench - MCP-Atlas adapter
benchmarks/mcp_atlas
Other components
- Agent client
- Weak model
- Strong model
- Tool client
Connections 31
- Agent client → HTTP endpoint: sends requests
README.md - HTTP endpoint → Session gateway: routes sessions
src/specagent/server.py - HTTP endpoint → Backend auth: configures auth
src/specagent/server.py - Session gateway → Weak model: drafts with
README.md - Session gateway → Strong model: reviews with
README.md - Session gateway → Tool client: returns tool steps
README.md - Session gateway → Context views: builds views
src/specagent/runtime/gateway.py - Session gateway → Action gating: classifies actions
src/specagent/runtime/gateway.py - Session gateway → Request evidence: collects evidence
src/specagent/runtime/gateway.py - Session gateway → Payload pruning: prunes payload
src/specagent/runtime/gateway.py - Session gateway → Verdict parser: parses verdict
src/specagent/runtime/gateway.py - Session gateway → Repair note: builds repair note
src/specagent/runtime/gateway.py - Session gateway → Prefix state: commits prefix
- Session gateway → Protocol records: uses records
src/specagent/runtime/gateway.py - Token accounting → Estimator labels: tags estimates
src/specagent/protocol/accounting.py - FLOPs estimator → Token accounting: estimates from usage
src/specagent/protocol/flops.py - FLOPs estimator → Estimator labels: uses labels
src/specagent/protocol/flops.py - HBM estimator → Token accounting: estimates from usage
src/specagent/protocol/hbm.py - HBM estimator → FLOPs estimator: uses model data
src/specagent/protocol/hbm.py - HBM estimator → Paper settings: loads settings
src/specagent/protocol/hbm.py - Cache report → Token accounting: reports ledger
src/specagent/protocol/cache_report.py - Resource estimates → Token accounting: uses ledger
src/specagent/protocol/resource_estimate.py - Resource estimates → Cache report: uses cache report
src/specagent/protocol/resource_estimate.py - Resource estimates → FLOPs estimator: computes FLOPs
src/specagent/protocol/resource_estimate.py - Resource estimates → HBM estimator: computes HBM
src/specagent/protocol/resource_estimate.py - Resource estimates → Paper settings: loads settings
src/specagent/protocol/resource_estimate.py - Resource estimates → Protocol records: uses records
src/specagent/protocol/resource_estimate.py - τ²-Bench adapter → HTTP endpoint: uses endpoint
- AutomationBench adapter → HTTP endpoint: uses endpoint
- VitaBench adapter → HTTP endpoint: uses endpoint
- MCP-Atlas adapter → HTTP endpoint: uses endpoint