Skip to content

feat: add configurable agent ID support#3

Merged
techartdev merged 3 commits intotechartdev:mainfrom
bmobytes:feature/configurable-agent-id
Mar 7, 2026
Merged

feat: add configurable agent ID support#3
techartdev merged 3 commits intotechartdev:mainfrom
bmobytes:feature/configurable-agent-id

Conversation

@bmobytes
Copy link

Summary

This PR adds support for configuring which OpenClaw agent the integration communicates with, rather than always defaulting to the implicit main agent.

The OpenClaw gateway already supports routing requests to specific agents via the x-openclaw-agent-id header. This PR wires that capability through the full HA integration stack.

Changes

const.py

  • Added CONF_AGENT_ID = "agent_id"
  • Added DEFAULT_AGENT_ID = "main"
  • Added ATTR_AGENT_ID = "agent_id" (for service calls)

api.py

  • OpenClawApiClient.__init__ now accepts agent_id: str = "main"
  • _headers() always includes x-openclaw-agent-id (gateway is unaffected when value is "main")
  • async_send_message and async_stream_message each accept an optional per-call agent_id override

config_flow.py

  • Manual setup step — new optional Agent ID text field (defaults to "main")
  • Options flowAgent ID field appears at the top of the options form so it can be changed at any time via Settings → Integrations → OpenClaw → Configure

__init__.py

  • async_setup_entry reads agent_id from options (preferred) or config data, and passes it to the API client
  • SEND_MESSAGE_SCHEMA gains an optional agent_id field so individual automation service calls can address a specific agent, overriding the configured default

services.yaml

  • send_message service now documents the new optional agent_id field

strings.json / translations/en.json

  • Labels added for the new agent_id option in both the manual config step and options flow
  • Service field translation added

Behaviour

Scenario Behaviour
agent_id not set / set to "main" Identical to current behaviour
agent_id set to "wish-bmo" in options All messages routed to that agent via x-openclaw-agent-id: wish-bmo
agent_id: "other-agent" in send_message service call Per-call override, all other calls unaffected

Testing

  1. Install updated integration
  2. Go to Settings → Integrations → OpenClaw → Configure
  3. Change Agent ID from main to another agent name
  4. Send a message via the Lovelace card or openclaw.send_message service — it should route to the configured agent
  5. Optionally pass agent_id in a service call to override per-message

Note: This PR was implemented with assistance from an AI coding agent (BMO) and reviewed by a human before submission. It is a bot-assisted contribution that has undergone human review.

BMO (OpenClaw) and others added 3 commits February 26, 2026 13:50
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.
Removed redundant assignment of agent_id from options.
@techartdev
Copy link
Owner

Hi @bmobytes !
Thank you for the contribution. I have pushed the changes directly into main as I had to do some tweaks in order to make reload possible each time agent is changed. Otherwise user must do it manually and may forgot to do it, which will result in agent not being changed. I will merge the PR being now empty so it will count your contribution.

@techartdev techartdev merged commit 6fc19d0 into techartdev:main Mar 7, 2026
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