Repository navigation
Conversation
…accounting Agent loop - Each iteration runs in a guard: an exception in an action handler is discarded with feedback to the model and the run continues; sweep, boundary and reserve handlers tolerate a non-dict feasibility / candidate_set. - The UI callback fires only when the iteration recorded a journal entry; otherwise a UI-only "discarded" card says why. The final re-emit of the last entry is removed (it duplicated the last card and, after rejected iterations, showed a stale lower-numbered card after the last one). - journal.discarded_actions records iterations that produced no entry (kind rejected / api_error / truncated / internal, feedback, stop_reason, raw response capped at 4000 characters). Entries and statistics are unchanged. - Responses cut at max_tokens get their own message and feedback; a modify that applies no command says so; modify entries keep skipped_commands. - Optional stall breaker: AGENTIGRID_STALL_LIMIT=N stops after N consecutive iterations without a new entry (off by default). Backends - Anthropic prompt caching of the per-session system prompt (llm.prompt_cache, default on; billing only). prompt_tokens stays the total input; cache writes and reads are reported separately. - UsageMeter counts every LLM call; totals are exported as journal llm_usage. - Models that reject `temperature` are retried once without it. - LLMResponse gains api_error, stop_reason, content_types and cache fields; AGENTIGRID_MAX_TOKENS overrides the output-token cap. UI and reports - Iterations shown as "N + base case" (summary_stats adds llm_iterations and has_base_case; total_iterations unchanged). - FAILED only for solves that did not converge, not for analysis / complete / sweep / contingency / explore entries or discarded proposals. - Sidebar checkbox for the stall breaker (unchecked by default). - Default Anthropic model claude-sonnet-4-20250514 (retired) -> claude-sonnet-4-6. Tests: new tests/llm/test_prompt_cache.py and tests/journal/test_iteration_count.py; 8 new tests in tests/agent_loop/test_agent_loop.py. Fast suite: 1103 passed, 12 skipped; the 2 failures are the existing OPFLOW fixture issues fixed by the genfuel PR. Co-Authored-By: Claude Opus 5.5 <[email protected]>
4 of 20 tasks
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.
Replaces #139 (fork PR, closed so CI can run).
Merge request type
Relates to
This MR updates
Summary
Makes AgentiGrid's agent loop robust to bad LLM output, fixes how the UI timeline reports such iterations, and adds LLM usage accounting. Found in long runs with local models (Ollama), where malformed or unparseable actions are common. All changes are in
agentigrid/.Agent loop (
engine/agent_loop.py):feasibility/candidate_set.resume.journal.discarded_actionsrecords each iteration that produced no entry: rejected / api_error / truncated / internal, the feedback,stop_reason, and the raw response (capped at 4,000 characters). Entries and summary statistics are unchanged.max_tokens; a modify that applies no command says so; modify entries keepskipped_commands.AGENTIGRID_STALL_LIMIT=Nstops after N consecutive iterations without progress. Off by default; a sidebar checkbox sets it.Backends (
backends/):llm.prompt_cache, default on). Billing only; the model sees the same text.prompt_tokensremains the total input; cache writes and reads are reported separately.UsageMetercounts every LLM call, including post-search analysis; totals are exported in the journal asllm_usage.temperatureare retried once without it.LLMResponsegainsapi_error,stop_reason,content_typesand cache token fields.AGENTIGRID_MAX_TOKENSoverrides the output-token cap.UI and reports:
summary_stats()addsllm_iterationsandhas_base_case;total_iterationsis unchanged.claude-sonnet-4-20250514(retired) →claude-sonnet-4-6.Testing: new
tests/llm/test_prompt_cache.pyandtests/journal/test_iteration_count.py; 8 new tests intests/agent_loop/test_agent_loop.py(4 of them fail on the previous agent loop).python -m pytest -m "not slow"fromagentigrid/without ExaGO binaries: 1103 passed, 12 skipped, 2 failed. The 2 failures are the OPFLOW fixture issues fixed by the genfuel PR (#137); with both applied: 1108 passed, 13 skipped. The changelog entry is inagentigrid/claude_code_changes.md.AI assistance: prepared with Claude (Anthropic); the commit carries
Co-Authored-By: Claude.Linked Issue(s)
None filed. Independent of #137; both apply cleanly in either order.