Skip to content

test: add unit tests for run_agent.py (AIAgent)#67

Merged
teknium1 merged 1 commit into
NousResearch:mainfrom
0xbyt4:test/add-run-agent-unit-tests
Feb 27, 2026
Merged

test: add unit tests for run_agent.py (AIAgent)#67
teknium1 merged 1 commit into
NousResearch:mainfrom
0xbyt4:test/add-run-agent-unit-tests

Conversation

@0xbyt4

@0xbyt4 0xbyt4 commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add 71 unit tests for run_agent.py (AIAgent class) covering 16 methods across 3 groups
  • Pure functions (26 tests): _has_content_after_think_block, _strip_think_blocks, _extract_reasoning, _clean_session_content, _get_messages_up_to_last_assistant, _mask_api_key_for_logs
  • State/structure methods (33 tests): __init__, interrupt mechanism, _hydrate_todo_store, _build_system_prompt, _invalidate_system_prompt, _build_api_kwargs, _build_assistant_message, _format_tools_for_system_message
  • Conversation loop pieces (12 tests): _execute_tool_calls, _handle_max_iterations, run_conversation (stop, tool calls, interrupt, invalid tool retry, empty content fallback, context compression)

Test plan

  • uv run pytest tests/test_run_agent.py -v — 71 passed in ~3s
  • uv run pytest -v — full suite 243 passed, no regressions

71 tests covering pure functions, state/structure methods, and
conversation loop pieces. OpenAI client and tool loading are mocked.
@teknium1 teknium1 merged commit 64eca85 into NousResearch:main Feb 27, 2026
sudo-yf pushed a commit to sudo-yf/hermes-agent that referenced this pull request Apr 5, 2026
…usResearch#67)

The webui stores display-only fields on messages (attachments, timestamp,
_ts) for UI rendering. These leaked into the conversation_history passed
to AIAgent.run_conversation(). Most providers ignore unknown fields, but
Z.AI/GLM tries to deserialize 'attachments' as its native ChatAttachments
type, causing HTTP 400 on every subsequent message after an image upload.

Fix: _sanitize_messages_for_api() creates a clean copy with only
API-standard keys (role, content, tool_calls, tool_call_id, name,
refusal) before passing to run_conversation(). Applied to both the
streaming path (streaming.py) and non-streaming path (routes.py).

Closes NousResearch#66

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
…t-tests

test: add unit tests for run_agent.py (AIAgent)
olympus-terminal pushed a commit to olympus-terminal/hermes-agent that referenced this pull request May 16, 2026
…t-tests

test: add unit tests for run_agent.py (AIAgent)
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
…t-tests

test: add unit tests for run_agent.py (AIAgent)
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.

2 participants