CowAgent’s highest-priority risk sits in its LLM protocol and model-integration layer: _call_llm_stream in agent/protocol/agent_stream.py carries a cyclomatic complexity of 120 and was touched 5 times in the last 30 days, earning an activity-weighted risk score of 20.3 — making it a live regression risk, not a cleanup backlog item. CowAgent is a multi-channel AI agent platform with 1,724 analyzed functions, 451 of which rank as critical — a concentration that signals systemic structural pressure across the codebase. Of those, 267 fall in the “fire” quadrant, meaning they are simultaneously complex and under active change, compounding the regression surface right now.
The table below ranks functions by activity-weighted risk — a score that multiplies structural complexity by recent commit frequency. A function that is both hard to understand (high cyclomatic complexity) and actively changing is a higher priority than one that is complex but untouched. CC = cyclomatic complexity (independent execution paths); ND = max nesting depth; FO = fan-out (distinct callees).
Top 5 Hotspots
| Function | File | Risk | CC | ND | FO |
|---|---|---|---|---|---|
_call_llm_stream | agent/protocol/agent_stream.py | 20.3 | 120 | 7 | 45 |
call_with_tools | models/gemini/google_gemini_bot.py | 19.9 | 124 | 11 | 23 |
on_handle_context | plugins/godcmd/godcmd.py | 19.3 | 191 | 7 | 51 |
_load_tools_from_init | agent/tools/tool_manager.py | 18.9 | 35 | 8 | 11 |
execute | agent/tools/bash/bash.py | 18.8 | 71 | 6 | 34 |
Hotspot Analysis
_call_llm_stream — agent/protocol/agent_stream.py
Based on its name and location in the agent protocol layer, this function almost certainly orchestrates streaming responses from a language model — managing incremental output chunks, likely handling multiple model backends and error conditions along the way. A cyclomatic complexity of 120 means there are at least 120 independent execution paths through it, each one a required test case and a potential regression surface. With a nesting depth of 7, a fan-out of 45 distinct callees, and 5 commits touching it in the last 30 days (days since last change: 0), this is CowAgent’s single highest-urgency function — complex, broadly coupled, and actively changing right now.
Recommendation: Before any refactoring, write characterization tests that capture current streaming behavior across representative input shapes; then extract the per-backend dispatch logic and the chunk-accumulation logic into dedicated private functions to bring CC below 20 and fan-out below 15.
call_with_tools — models/gemini/google_gemini_bot.py
This function, situated in the Gemini model integration, almost certainly manages the tool-calling protocol between CowAgent and Google’s Gemini API — routing tool invocations, handling responses, and likely managing retries or multi-turn cycles. Its cyclomatic complexity of 124 is the highest in the analyzed set, its nesting depth of 11 is an extreme outlier (strong refactoring signal is ND 8+), and it has been touched twice in the last 30 days with an activity-weighted risk score of 19.9. The combination of god-function coupling, exit-heavy branching, and ongoing active development makes this a live regression risk: every commit navigates 124 execution paths and 11 levels of nested logic.
Recommendation: Map the fan-out of 23 callees to identify which tool-dispatch branches can be extracted into a dedicated tool-response handler; target the deepest nesting levels first, as collapsing even two levels of nesting will make the remaining logic substantially easier to test and reason about.
Patterns Found
Antipatterns detected across the top functions in this snapshot:
| Pattern | Occurrences |
|---|---|
complex_branching | 10 |
deeply_nested | 10 |
exit_heavy | 10 |
god_function | 10 |
long_function | 9 |
These labels belong to two tiers — Tier 1 (structural): complex_branching, deeply_nested, exit_heavy, long_function, god_function. Tier 2 (relational/temporal): hub_function, cyclic_hub, middle_man, neighbor_risk, stale_complex, churn_magnet, shotgun_target, volatile_god.
Key Takeaways
_call_llm_streaminagent/protocol/agent_stream.pyhas CC 120, fan-out 45, and was touched 5 times in the last 30 days — write characterization tests covering its streaming paths before the next commit lands.call_with_toolsinmodels/gemini/google_gemini_bot.pyhas the deepest nesting in the dataset at ND 11; collapsing the innermost nesting levels first will yield the fastest improvement in readability and testability without requiring a full rewrite.
Reproduce This Analysis
git clone https://github.com/zhayujie/CowAgent
cd CowAgent
git checkout fb341b869b14339e92aa110d019ded7a90707817
hotspots analyze . --mode snapshot --explain-patterns --force
To run the same analysis on your own codebase, run hotspots analyze . --mode snapshot in any local git repo — no configuration required.
Hotspots highlights structural and activity risk — not “bad code.” Findings are a prioritization aid, not a bug predictor. Editorial policy →