feat: add configurable agent ID support

Allow users to configure which OpenClaw agent the integration communicates
with, instead of always defaulting to the implicit 'main' agent.

Changes:
- const.py: add CONF_AGENT_ID, DEFAULT_AGENT_ID='main', ATTR_AGENT_ID
- api.py: accept agent_id in constructor; _headers() now includes the
  x-openclaw-agent-id header on every request; async_send_message and
  async_stream_message accept an optional per-call agent_id override
- config_flow.py: expose agent_id as a text field in both the manual
  setup step and the options flow (Settings → Integrations → Configure)
- __init__.py: read agent_id from options/data and pass it to the API
  client; add optional agent_id field to the send_message service schema
  so automations can address a specific agent per-call
- services.yaml: document the new agent_id field on send_message
- strings.json / translations/en.json: add UI labels for the new option

The gateway routing header x-openclaw-agent-id is always sent; when
agent_id is 'main' (the default) the gateway behaviour is unchanged.
A per-call override on send_message takes precedence over the config.

Implemented with assistance from an AI coding agent (BMO) with human
review. Bot-assisted contribution reviewed by a human before submission.
This commit is contained in:
BMO (OpenClaw)
2026-02-26 13:50:07 -06:00
parent 9bcac79241
commit fa0af8da60
7 changed files with 71 additions and 6 deletions
+11
View File
@@ -34,6 +34,7 @@ from .const import (
ADDON_SLUG,
ADDON_SLUG_FRAGMENTS,
CONF_ADDON_CONFIG_PATH,
CONF_AGENT_ID,
CONF_GATEWAY_HOST,
CONF_GATEWAY_PORT,
CONF_GATEWAY_TOKEN,
@@ -52,6 +53,7 @@ from .const import (
BROWSER_VOICE_LANGUAGES,
CONTEXT_STRATEGY_CLEAR,
CONTEXT_STRATEGY_TRUNCATE,
DEFAULT_AGENT_ID,
DEFAULT_GATEWAY_HOST,
DEFAULT_GATEWAY_PORT,
DEFAULT_CONTEXT_MAX_CHARS,
@@ -411,6 +413,7 @@ class OpenClawConfigFlow(ConfigFlow, domain=DOMAIN):
CONF_GATEWAY_TOKEN: token,
CONF_USE_SSL: use_ssl,
CONF_VERIFY_SSL: verify_ssl,
CONF_AGENT_ID: user_input.get(CONF_AGENT_ID, DEFAULT_AGENT_ID),
},
)
if "base" not in errors:
@@ -429,6 +432,7 @@ class OpenClawConfigFlow(ConfigFlow, domain=DOMAIN):
vol.Required(CONF_GATEWAY_TOKEN): str,
vol.Optional(CONF_USE_SSL, default=False): bool,
vol.Optional(CONF_VERIFY_SSL, default=True): bool,
vol.Optional(CONF_AGENT_ID, default=DEFAULT_AGENT_ID): str,
}
),
errors=errors,
@@ -453,6 +457,13 @@ class OpenClawOptionsFlow(OptionsFlow):
selected_provider = options.get(CONF_VOICE_PROVIDER, DEFAULT_VOICE_PROVIDER)
schema: dict[Any, Any] = {
vol.Optional(
CONF_AGENT_ID,
default=options.get(
CONF_AGENT_ID,
self._config_entry.data.get(CONF_AGENT_ID, DEFAULT_AGENT_ID),
),
): str,
vol.Optional(
CONF_INCLUDE_EXPOSED_CONTEXT,
default=options.get(