Skip to content

Agent model/budget env tuning + self-correction retry - #9

Merged
7vignesh merged 3 commits into
mainfrom
feat/agent-tuning-and-repair
Oct 14, 2026
Merged

7vignesh merged 3 commits into
mainfrom
feat/agent-tuning-and-repair

Conversation

@7vignesh

Copy link
Copy Markdown
Owner

Summary

Two improvements to how the agent pipeline runs, aimed at making it work well on free/weak models without editing source.

  • Make agent model, output token budget, and compression env-tunable (defaults unchanged).
  • Add a single self-correction pass when an agent returns invalid output, instead of failing the whole job.

Changes

1. Env-tunable agent config (packages/agents/src/config/agent.configs.ts)

Model was hardcoded to openai/gpt-4o-mini; output caps and compression were fixed in source. New opt-in env overrides:

  • STACKFORGE_MODEL / STACKFORGE_MODEL_<AGENT> - global or per-agent model
  • STACKFORGE_OUTPUT_SCALE - scale factor on maxOutputTokens and tokenBudget
  • STACKFORGE_COMPRESSION - global compression level override

Defaults are identical when env is unset, so existing behaviour and tests are preserved. Documented in .env.example.

2. Self-correction retry (packages/agents/src/workflow/engine.ts)

Weak/free models frequently emit malformed JSON, which previously failed the entire job on first validation error. On validateStepOutput failure, the engine now runs one repair call (shows the model its bad output + the error, asks for corrected strict JSON) and re-validates. If repair also fails, the original error propagates as before.

Testing

  • Typecheck: clean across all 8 packages
  • Tests: 27 agent tests + API/other suites pass; added a test proving recovery from invalid planner output via exactly one repair pass with no agent_failed emitted
  • E2E (mock provider) with STACKFORGE_OUTPUT_SCALE=1.5 STACKFORGE_COMPRESSION=low: full pipeline completes, download produces a valid ZIP

…nable

Agent model was hardcoded to openai/gpt-4o-mini and output caps/compression
were fixed in source. Add opt-in env overrides so a free OpenRouter model and
looser budgets can be used without editing code:

- STACKFORGE_MODEL / STACKFORGE_MODEL_<AGENT>: per-agent or global model
- STACKFORGE_OUTPUT_SCALE: scale factor on maxOutputTokens and tokenBudget
- STACKFORGE_COMPRESSION: global compression level override

Defaults are unchanged when env is unset, so existing behaviour and tests
are preserved. Document the new vars in .env.example.
Weak/free models frequently emit malformed or incomplete JSON, which
previously failed the entire job on the first validation error. When
validateStepOutput throws, run one repair call that shows the model its own
output plus the validation error and asks for corrected strict JSON, then
re-validate. If the repair also fails, the original failure propagates as
before.

Add a test proving the engine recovers from an invalid planner output via
exactly one repair pass with no agent_failed event emitted.
@vercel

vercel Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
stackforge-web Ready Ready Preview Oct 14, 2026 2:31pm UTC

The 'remove husky pre-commit hooks' change dropped husky from package.json
but left it in bun.lock, so 'bun install --frozen-lockfile' (used in CI)
failed. Regenerate the lockfile to drop the stale husky entry.
@7vignesh
7vignesh merged commit c38020e into main Oct 14, 2026
3 checks passed
@7vignesh
7vignesh deleted the feat/agent-tuning-and-repair branch October 14, 2026 14:39

This branch was successfully deployed

1 active deployment
Preview — 75ac30b5 Deployed Oct 14, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant