Skip to content

AIAgent / init_agent

源码版本v2026.7.20

Responsibility

init_agent is the agent's "assembly workshop": it injects provider, toolsets, compression threshold, custom provider extra_body, memory and learning components into the agent instance so it has every dependency needed to run a turn of conversation. The AIAgent class itself is just a thin shell around its output.

Key Files

Data Flow

  1. AIAgent.__init__ (run_agent.py:423) collects constructor parameters as-is.
  2. It calls init_agent:276, which in order:
  3. The assembled agent exposes the run_conversation method (run_agent.py:6350), forwarding to the module-level agent/conversation_loop.py:588.
  4. The gateway's GatewayRunner (gateway/run.py:3029) holds the assembled agent and hands inbound messages to it.

Summary

init_agent is the translation layer from config to runtime; every startup-time decision (provider selection, compression strategy, toolsets toggles) is settled here once. Afterward the agent enters a stateless "feed message → run loop" rhythm and no longer revisits config.

Unofficial community learning site. Content based on the MIT-licensed NousResearch/hermes-agent source.