Repository navigation
Feat(Agent): Add built-in LangGraph agent with LiteLLM routing and AI spend tracking - #10
Merged
vsn411 merged 1 commit intoSep 21, 2026
Conversation
Adds a `secfoo` agent adapter that runs skills in-process via LangGraph, routing every model call through LiteLLM so any provider/model works through one interface. Per-run cost is captured from LiteLLM and stored alongside each run, surfaced via `secfoo cost`, the `list`/run-detail CLI output, the web dashboard, and the cloud-sync payload. Co-Authored-By: Claude Sonnet 5 <[email protected]>
geet038
added a commit
that referenced
this pull request
Sep 21, 2026
Rebuild the api agent's run as a LangGraph graph (collect_files -> assess -> report check), with LiteLLM still the only model gateway. If a report comes back without the `**Overall risk rating:**` line every output contract requires, the graph asks the model once to reformat its own draft -- without resending the source, so the retry stays cheap. Tokens and cost add up across both calls. LiteLLM now retries rate limits and transient errors itself (num_retries=3); running several skills at once previously failed on OpenAI's rate limit. Fold in the useful parts of PR #10: - tokens and cost in the cloud-sync payload and create_completed_run - `secfoo cost --project`, a README section, config.example.toml hint - UTF-8 for every text read/write, not just runner's report writes. Report reads use errors="replace" so reports written by older versions in the Windows code page still render instead of crashing. The suite now gives the same result with or without PYTHONUTF8. langgraph joins litellm in the `api` extra, and dev (litellm stays faked in tests, so CI doesn't need it). Co-Authored-By: Claude Opus 5 <[email protected]>
geet038
added a commit
that referenced
this pull request
Sep 21, 2026
The conflict resolution kept both sides in several places: - repository.py create_completed_run: two INSERT statements spliced together (unclosed paren -> SyntaxError, every test failed) and a duplicate cost_usd parameter - repository.py complete_run: a leftover SQL line from #10 after the UPDATE string, so execute() received three arguments - schema.sql: cost_usd declared twice (duplicate column name) - cli.py: two `cost` commands and two Cost columns in `list` - overview/project/run_detail templates: both cost renderings; README: interleaved intro sentence and an unclosed code fence Keep one version of each (the one with tokens and "-" for unknown cost), drop the now-unused total_cost_usd from the overview route, and point #10's two `cost` CLI tests at the current command. Both the `secfoo` and `codex` agents from main are kept. Co-Authored-By: Claude Opus 5 <[email protected]>
5 tasks done
AdithKB
added a commit
to AdithKB/secfoo
that referenced
this pull request
Oct 3, 2026
…odel) src/secfoo/agents/secfoo.py was the original Initiative-2 draft (PR secfoo-com#10). PR secfoo-com#11 fixed the exact bug it has -- the agent never reads the target's files, so the model reviews nothing and fabricates a report -- but fixed it in a new, separate file (api.py) and never removed this one. Both have been registered and independently selectable via --agent ever since, with no indication either is broken. Reproduced twice against we45/Vulnerable-Flask-App (SAST and Secret Scanning): --agent secfoo returns "Confirmed" findings at file paths that don't exist anywhere in the target (app/db.py, app/upload.py, deploy/ci.yml), because build_graph's _State/run() never wires the resolved workdir into the model call at all -- collect_files() (the function that actually reads source) is never called from this file. The adapter's own test asserts this as correct behavior (messages == [{"role": "user", "content": "review this target"}]), so CI can't catch it. --agent api is the real, fixed implementation and needs no changes. This just removes the dead duplicate and its now-stale references: registry, AgentId enum, __init__ exports, its test, and two docs spots (README's duplicate "built-in LangGraph agent" section, and config.example.toml's three conflicting `agent =` example lines). Full suite: 700 passed (down from 702 -- exactly the 2 tests removed with the dead file). bandit clean on the touched agent files. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
secfooagent adapter (src/secfoo/agents/secfoo.py) that runs skills in-process via LangGraph, routing every model call through LiteLLM so any provider/model LiteLLM supports works through one interface (SECFOO_MODEL, defaultopenai/gpt-4o-mini). Registered alongside the existingclaude/agent/agy/geminiadapters.AgentResult.cost_usd(from LiteLLM'scompletion_cost) is threaded through the runner into a newruns.cost_usdSQLite column, and surfaced via:secfoo cost/secfoo cost --project <name>CLI commandsecfoo listpush_run)OPENAI_API_KEY/ANTHROPIC_API_KEY/GEMINI_API_KEY), matching this repo's existing convention.Test plan
pytest tests— 640 passed. The only failures (6) are pre-existing onmainand untouched by this diff (a Windowsos.chmodPOSIX-permissions test, and pre-existing mermaid-diagram/depth tests unrelated to any file this PR touches).tests/test_agents/test_secfoo.py(LangGraph/LiteLLM wiring, cost capture, availability check),secfoo costCLI tests, storage round-trip tests forcost_usd/total_cost_usd, cloud payload test.secfoo run --skill secret-scanning --agent secfoo --depth quickend-to-end against a real OpenAI key, then verifiedsecfoo cost,secfoo list, and the dashboard (overview/project/run-detail pages) all show the recorded spend correctly.bandit -r src/secfoo/agents/secfoo.py src/secfoo/cli.py— no issues.🤖 Generated with Claude Code