tools_main
Tools service entry point — dedicated, isolatable tool-execution worker.
Runs ToolsService, a StargazerService whose
sole job is to execute tools on behalf of the inference tier. It is the only
process that imports the tool handler modules in tools/: on boot it loads the
full ToolRegistry, publishes the tool catalog to Redis (so
inference can present tools without importing them), and consumes tool-execution
requests off sg:stream:tools (group sg:tools, load-balanced across
instances). Each request reconstructs a ToolContext from
the request’s identity fields plus this service’s shared managers and a
ProxyPlatformAdapter (so tool sends still publish to
the gateway and raw-SDK ops still delegate to it), runs the tool, and replies on
the originating worker’s reply stream with the result plus the write-back
channels (sent_files media bytes, injected_tools, sent_rich_messages).
Deliberately lighter than inference: no message processor, no swarm/subagent
system, no presence manager, no inbound consumer. Compound tools that spawn
nested LLM loops stay pinned to inference (INFERENCE_PINNED_TOOLS); the
OpenRouterClient wired here exists only for the embedding/KG managers some
delegated tools use. Launched standalone (python tools_main.py) by
scripts/systemd/stargazer-tools.service.
- class tools_main.ToolsService(config, redis_client, instance_id, use_health_server=True)[source]
Bases:
StargazerServiceDedicated tool-execution service (service tier
"tools").- get_adapter(platform_name)[source]
Return a proxy adapter so tool sends publish to the gateway’s stream.
- Return type:
- Parameters:
platform_name (str)
- async on_start()[source]
Subclass hook for tier-specific startup, run during boot.
Abstract extension point invoked by
boot()(its phase 3-7) after the Redis ping succeeds but before registry registration and the health server start, so each tier can stand up its own machinery – loading tools, building platform adapters, wiring stream consumers, initializing observability – on a verified Redis connection. Has no behavior here; it must be overridden.Called by
boot(); the concrete implementations live in the*_main.pyservice classes (InferenceService.on_start,GatewayService.on_start, etc.) and are exercised directly by thetests/core/migrationsuite.- Return type:
- async run()[source]
Subclass hook for the main service loop, run after boot.
Abstract extension point that holds the service’s long-lived work – typically consuming a Redis stream or serving HTTP – and is expected to block until shutdown is signalled. Each tier’s
mainawaits this immediately afterboot()returns, so it defines what the process actually does for its lifetime. Has no behavior here; it must be overridden.Called by each microservice’s
mainviaawait service.run()(ininference_main.py,gateway_main.py,web_main.py,consolidation_main.py,agents_main.py), right afterservice.boot().- Return type:
- async on_stop()[source]
Subclass hook for tier-specific cleanup, run during shutdown.
Abstract extension point invoked by
shutdown()after the health server is stopped and the instance is deregistered, giving each tier a place to release whaton_start()andrun()stood up (platform adapters, schedulers, consumers, sockets). Has no behavior here; it must be overridden.Called by
shutdown(); concrete implementations live in the*_main.pyservice classes (e.g.WebService.on_stopdrives a graceful uvicorn exit,GatewayService.on_stopstops platform adapters) and are covered bytests/core/migration.- Return type: