Skip to content

feat(sdk): let one agent use several accounts of one integration - #8859

Merged
mmabrouk merged 10 commits into
release/v0.133.1from
feat/gateway-multi-account
Dec 4, 2026
Merged

mmabrouk merged 10 commits into
release/v0.133.1from
feat/gateway-multi-account

Conversation

@mmabrouk

@mmabrouk mmabrouk commented Dec 4, 2026

Copy link
Copy Markdown
Member

Context

A project can hold several connections of one integration, for example a work Gmail and a personal Gmail. One agent could use only one of them. A second gateway_connection entry for the same integration was refused by the SDK ("Duplicate gateway connection entry"), by the change-set engine (ITEM_ALREADY_EXISTS), and the runner policy could hold only one entry per integration.

This PR is the backend part of the approved OpenSpec change multiple-accounts-per-integration (included in this PR under openspec/changes/). Each entry can now carry an account name, such as work. The model passes that name to run_tool, and the runner sends the call with that entry's connection. The playground part (task 5) is a separate PR.

An "account" in this PR means the author's name for one entry. It is not the provider account ID and not connection.account_source.

Changes

Saved entry (SDK). A gateway_connection entry accepts an optional account. Several entries of one integration are valid when every one has a different account and a different connection. An integration has at most one entry with connection.account_source: "user". An integration with one entry needs no account.

Resolved policy (SDK to runner wire). An entry with an account is keyed <integration>:<account> and carries integration and account. An entry without an account keeps its old key and fields.

Before, and still for an agent without accounts:

"integrations": {"gmail": {"provider": "composio", "connection": "gmail-main-7mx", ...}}

With two Gmail accounts:

"integrations": {
  "gmail:work":     {"integration": "gmail", "account": "work",     "connection": "gmail-main-7mx", ...},
  "gmail:personal": {"integration": "gmail", "account": "personal", "connection": "gmail-secondary-xyz", ...}
}

Runner. The runner reads an entry's integration from its integration field, else from its key, and never splits the key. For an integration whose entries carry account, run_tool must name one. The runner refuses the call when account is missing or unknown, and it lists the account names in the refusal. It requires account even when only one named entry reached the run, so an account whose connection was unavailable at run start does not turn the other one into a silent default. Each account keeps its own permissions. Search hits list in accounts the account names that may run the tool.

Model-facing schema and prompt (SDK). run_tool gets an optional account argument only when at least one entry has an account. search_tools does not change. The "Connected integrations" prompt section lists gmail (personal, work) and adds two lines on how to pass account.

Change-set key (API). An entry with account has the key gateway_connection:<provider>:<integration>:<account>. An entry without one keeps gateway_connection:<provider>:<integration>. add_item refuses a Gmail entry next to an existing Gmail entry when either of them has no account, and the hint tells the builder to remove the existing entry and add both with account.

Docs. The contracts in docs/design/composio-tools-rework/ (contracts.md sections 1, 4, 5 and 7, runtime-tools.md), data-model.md, the runner interface page and the public agent configuration reference now describe the account form.

Scope and risk

  • This changes the runner and the /run wire. Release the runner first, then the SDK and the agent service. A runner older than this PR that receives a gmail:work key finds no gmail entry and refuses the call as not connected, so a version mismatch fails closed and no tool runs on the wrong mailbox.
  • Agents without account send the same run payload as before. A new test builds the run request through the real resolver and compares it with the existing golden run_request.gateway_connection.json, which is unchanged. A separate check built a Gmail plus Slack agent with the release branch code and with this branch, and the two payloads were byte-identical.
  • The first account on an agent changes its run_tool schema once, so its warm session restarts once.
  • The playground still shows one row per integration and cannot add a second account yet (task 5, separate PR). An author can only add a second account by hand or through the builder agent until then.

Tests

  • Runner: pnpm test (303 files, 4897 tests) and pnpm run typecheck pass. New tests/unit/gateway-multi-account.test.ts covers routing per account, missing and unknown account, one named account left after resolve, an account on an integration without accounts, per-account permissions, approval scope and the approval card text, search accounts, the unscoped search toolkit versions, and suggestion filtering per account. wire-contract.test.ts checks the new golden with a typed fixture.
  • SDK: the full unit folder passes (4163 passed). New tests cover the validation rules, resolver keying, the run_tool schema, the prompt section, and both goldens through the real resolver.
  • API: pytest oss/tests/pytest/unit -k change_set passes (306), and the full API unit folder passes (12302).
  • openspec validate multiple-accounts-per-integration --strict passes.

How to QA

This needs a dev stack with the runner, the agent service and the API from this branch, and a project with two Gmail connections.

  • Write an agent config by hand (the playground cannot add the second account yet) with two Gmail entries, account: "work" and account: "personal", each on its own connection. Ask the agent to read the latest email from the personal account. The run goes through the personal connection.
  • Set SEND_EMAIL to ask on work and deny on personal. Ask the agent to send an email from work. The approval card shows gmail (work).SEND_EMAIL. Ask it to send from personal. The call is refused.
  • Ask the agent to send an email without saying which account. Expect one refused call that lists personal, work, then a retry with an account, or a question to you.
  • Regression: an agent with one Gmail entry and no account works as before, and its run_tool schema has no account field.

Interface reference

Contract Where Shape
Entry account saved gateway_connection entry, top level Optional string, ^[a-z0-9][a-z0-9_-]{0,31}$. Required on every entry of an integration with several entries; unique per integration.
run_tool.account model-facing input schema Optional string, placed after integration, present only when an entry of the agent has account. required stays integration, tool, arguments.
Search hit accounts search result written back to the model Sorted account names where the tool is allow or ask. Only for integrations whose entries carry account. connected_integrations stays plain integration names.
gatewayPolicy key form /run request, gatewayPolicy.integrations Key <integration> for an entry without account; <integration>:<account> for an entry with one. The key is opaque.
gatewayPolicy entry fields same New optional integration and account, present only on an account entry.
Change-set key item_key("tools", entry) in the API gateway_connection:<provider>:<integration>:<account> with account; gateway_connection:<provider>:<integration> without.

New model-facing text, shown for an agent with Gmail accounts personal and work and one Slack entry:

gmail has several accounts on this agent: personal, work. Pass `account`.
The account 'sales' is not configured for gmail on this agent. Configured accounts: personal, work. Pass one of them as `account`.
The account 'work' is not configured for slack on this agent. slack has no named accounts: call `run_tool` without `account`.

Two prompt lines, added only for an agent with accounts:

- An integration listed with account names in brackets has several accounts. Pass `account`
  with one of those names on every `run_tool` call for it. A search result lists in
  `accounts` the accounts that may run that tool.
- A refusal that says `account` is missing or not configured is the one refusal you correct:
  call `run_tool` again with one of the listed account names. Every other refusal is final.

@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

📘 Docs preview

Status ✅ Ready
Preview https://pr-8859-agenta-docs-preview.mahmoud-637.workers.dev/docs/
Inspect Actions run
Commit 43719cc23d29c4003d5c1ee043e331ffe23521f8

Pages changed in this pull request

This comment updates in place on every push.

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Configure multiple connections for the same integration using distinct account names.
    • Select an account when running tools. Calls with a missing or unavailable account are declined with guidance.
    • Search results and tool guidance show available accounts; permissions and approval details apply to the selected account.
    • Single-connection integrations can continue using existing configurations without an account name.
    • Account-specific connections are identified separately in change sets.
  • Bug Fixes
    • Invalid multi-account configurations, including duplicate account names or connection references, are rejected.
  • Documentation
    • Updated configuration and integration guides with account naming rules and examples.

This change supports multiple named gateway accounts for one integration. The SDK and runner carry account identity through policy resolution, tool calls, search, and execution. Gateway change-set keys include the account when present, while single unnamed entries retain their existing key format.

Changes: Gateway multi-account support

Layer / File(s) Summary
Multi-account contract and requirements
docs/design/composio-tools-rework/*, docs/design/agent-workflows/interfaces/cross-service/service-to-agent-runner.md, docs/docs/reference/agents/01-agent-configuration.mdx, openspec/changes/multiple-accounts-per-integration/*
The contracts and specifications describe account naming, validation, account-qualified policy entries, conditional run_tool selection, search results, and behavior for unnamed entries.
SDK account configuration and guidance
sdks/python/agenta/sdk/agents/tools/*, sdks/python/agenta/sdk/agents/platform/*, sdks/python/agenta/sdk/agents/platform_instructions.py, sdks/python/agenta/sdk/agents/dtos.py, sdks/python/agenta/sdk/agents/adapters/*, sdks/python/oss/tests/pytest/unit/agents/*
The SDK validates account names and entry groups, resolves account-specific policy entries, conditionally adds account to run_tool, and supplies account names to platform guidance. Tests and fixtures cover named and unnamed entries.
Runner account routing and search
services/runner/src/protocol.ts, services/runner/src/tools/gateway-policy.ts, services/runner/src/tools/relay.ts, services/runner/tests/unit/*
The runner selects policy entries by integration and account, refuses missing or unknown accounts, and includes reachable account names in search results. Relay execution carries the selected policy key and account.
Account-qualified change-set keys
api/oss/src/core/workflows/change_set.py, api/oss/src/core/workflows/service.py, api/oss/tests/pytest/unit/workflows/test_change_set.py
Gateway change-set keys include a nonempty account. Persisted gateway entries receive configuration validation. Tests cover separate replacement of named entries and invalid or conflicting entries.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller as run_tool caller
  participant Policy as gateway-policy.ts
  participant Relay as relay.ts
  participant Connection as Selected gateway connection
  Caller->>Policy: integration, tool, and account
  Policy->>Relay: GatewayRunTarget with policyKey and account
  Relay->>Connection: Dispatch selected account's tool call
  Connection-->>Relay: Tool result
Loading
Merge Risk: Minimal · up to 43719

The change lets one agent use several accounts of the same integration, and agents with a single unnamed entry keep their existing behavior. The earlier concerns about the builder instructions and the refusal-recovery wording are addressed. Merge-readiness risk is low; release the runner before the SDK and agent service, as the PR describes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "feat(sdk): let one agent use several accounts of one integration" matches the main change: agents can hold several gateway_connection entries for one integration, each with an optional acco…
Description check Passed The description explains the problem (one agent could use only one connection per integration), the approach (an optional account name per gateway_connection entry, keyed as integration:account in res…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat(sdk): let one agent use several accounts of one integration" matches the main change: agents can hold several gateway_connection entries for one integration, each with an optional account name, and the runner and SDK route calls by account. The title is specific and concise, though the change also spans the API, runner, and docs.

Full details: Description check

Explanation

The description explains the problem (one agent could use only one connection per integration), the approach (an optional account name per gateway_connection entry, keyed as integration:account in resolved policy), the runner and run_tool behavior, rollout order, tests, and QA steps. It is directly related to the changeset.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 2d2a4ee and 43719cc.

Files selected for processing: 4

  • docs/design/composio-tools-rework/runtime-tools.md
  • sdks/python/agenta/sdk/agents/platform/gateway.py
  • sdks/python/agenta/sdk/agents/platform_instructions.py
  • sdks/python/oss/tests/pytest/unit/agents/golden/run_request.gateway_connection.multi_account.json

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Railway Preview Environment

Item Value
Status stopped
Commit 43719cc23d29c4003d5c1ee043e331ffe23521f8
Manual expiry (UTC) Not granted
CI deadline (UTC) Not granted
Workflow https://github.com/Agenta-AI/agenta/actions/runs/47359426014

Dependent tests finished. Post /preview for manual review. Environment absence verified; retained storage requires separate provider accounting.

Post /preview as a new comment to request a one-hour preview. Repeating it while active does not extend the hour.
Preview data is disposable. Expiry is enforced by the next successful cleanup sweep, not an exact timer.
Environment deletion stops its compute. Provider-retained storage and permanent services may still be billed.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments

Major 1
  1. Duplicate connection slugs can be saved across named accounts.
Minor 3
  1. State the first-character restriction.
  2. Account availability changes can restart warm sessions twice.
  3. Field edits can persist a mixed named and unnamed integration.
Outside diff 1
  1. Update the build loop to permit multiple accounts.
    sdks/python/agenta/sdk/agents/adapters/agenta_builtins.py, lines 753–754 · 🎯 Functional Correctness · ⚡ Quick win
    The new reference permits one entry per account, but this build loop still instructs the builder to add “ONE” entry “per integration.” For a request to configure work and personal Gmail, these instructions conflict.
    Change this rule to one entry per account. Require distinct account names when several entries share an integration. Keep unnamed single-entry configurations valid.
Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7866b1d and 5f2c34f.

Files selected for processing: 34

  • api/oss/src/core/workflows/change_set.py
  • api/oss/tests/pytest/unit/workflows/test_change_set.py
  • docs/design/agent-workflows/interfaces/cross-service/service-to-agent-runner.md
  • docs/design/composio-tools-rework/contracts.md
  • docs/design/composio-tools-rework/data-model.md
  • docs/design/composio-tools-rework/runtime-tools.md
  • docs/docs/reference/agents/01-agent-configuration.mdx
  • openspec/changes/multiple-accounts-per-integration/design.md
  • openspec/changes/multiple-accounts-per-integration/proposal.md
  • openspec/changes/multiple-accounts-per-integration/review-loop.md
  • openspec/changes/multiple-accounts-per-integration/specs/gateway-multi-account/spec.md
  • openspec/changes/multiple-accounts-per-integration/tasks.md
  • sdks/python/agenta/sdk/agents/adapters/agenta_builtins.py
  • sdks/python/agenta/sdk/agents/adapters/harnesses.py
  • sdks/python/agenta/sdk/agents/dtos.py
  • sdks/python/agenta/sdk/agents/platform/gateway.py
  • sdks/python/agenta/sdk/agents/platform/op_catalog.py
  • sdks/python/agenta/sdk/agents/platform_instructions.py
  • sdks/python/agenta/sdk/agents/tools/compat.py
  • sdks/python/agenta/sdk/agents/tools/models.py
  • sdks/python/agenta/sdk/agents/utils/wire.py
  • sdks/python/agenta/sdk/agents/wire_models.py
  • sdks/python/oss/tests/pytest/unit/agents/golden/run_request.gateway_connection.multi_account.json
  • sdks/python/oss/tests/pytest/unit/agents/platform/test_gateway_connection_resolve.py
  • sdks/python/oss/tests/pytest/unit/agents/platform/test_gateway_multi_account.py
  • sdks/python/oss/tests/pytest/unit/agents/test_harness_adapters.py
  • sdks/python/oss/tests/pytest/unit/agents/test_platform_instructions.py
  • sdks/python/oss/tests/pytest/unit/agents/test_wire_contract.py
  • sdks/python/oss/tests/pytest/unit/agents/tools/test_gateway_connection_config.py
  • services/runner/src/protocol.ts
  • services/runner/src/tools/gateway-policy.ts
  • services/runner/src/tools/relay.ts
  • services/runner/tests/unit/gateway-multi-account.test.ts
  • services/runner/tests/unit/wire-contract.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@mmabrouk

mmabrouk commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

🤖 The AI agent says:

Review loop result for head 90b54ae225e2f1636bb49bc280fb8fc11d63e000 (base 7866b1dabd630a2b8bb8bf8a8ecb6fd16a945250), 3 rounds. Round 3 reviewed only the round 2 fixes.

Lens Final rating
Simplify Low
Slop Low

Fixed:

  • The change-set engine had its own copy of one account rule. The commit gate now runs the SDK list rules on every gateway_connection entry, so a duplicate account, a duplicate connection, a bad account name, or an entry without account beside another entry fails at commit, not at the next run.
  • The resolver now fails the run when two account slices of one integration return different toolkit versions.
  • The item_already_exists hint now tells the model to remove the entry without account and add one entry per account. Before, it pointed to replace_item, which drops the first account.
  • Stale docstrings and comments were updated, _check_single_entries became _check_list_rules, a dead optional chain was removed, and test imports moved to module level.

Left on purpose:

  • One-pass rewrite of filterGatewaySearchResult: the two passes are clear and the rewrite changes no behavior.
  • Inlining policyEntryIntegration: it is the one owner of the rule "the integration field, else the key".

@mmabrouk

mmabrouk commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

🤖 The AI agent says:

Review loop result for head 90b54ae225e2f1636bb49bc280fb8fc11d63e000 (base 7866b1dabd630a2b8bb8bf8a8ecb6fd16a945250), 3 rounds. Round 3 reviewed only the round 2 fixes.

Lens Final rating
Naming Low

Fixed:

  • "Several accounts" named a different condition from the one the code checks. The runner refusal now says "gmail on this agent needs an account: personal, work. Pass account." The prompt, the protocol comments, the docs and the golden file use the same condition.
  • The design now defines "account entry" (an entry with account), and "unnamed account", "unnamed integration" and "named entry" are gone.
  • The stale-key warning shows gmail (work), not the opaque policy key.
  • gateway_integrations became gateway_accounts_by_integration, and _check_single_entries became _check_list_rules.

Left on purpose:

  • Which layer owns the account name pattern for the frontend: this goes to the frontend PR.

@mmabrouk

mmabrouk commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

🤖 The AI agent says:

Review loop result for head 90b54ae225e2f1636bb49bc280fb8fc11d63e000 (base 7866b1dabd630a2b8bb8bf8a8ecb6fd16a945250), 3 rounds. Round 3 reviewed only the round 2 fixes with the correctness lens; security was Low in rounds 1 and 2. The correctness rounds also checked the changed interfaces against the interface design rules.

Lens Final rating
Correctness Low
Security Low

Fixed: no correctness or security change was needed. The commit gate and toolkit version fixes from the other lens sets were checked in round 2 and round 3.

Left on purpose:

  • The build kit text (the commit_revision description and the build-an-agent skill) now explains account, so the payload of every agent with the build kit changes, and warm sessions rebuild once. The rule "an agent without account names keeps a byte-identical payload" was read as the payload made from the agent's own configuration, which this PR keeps byte-identical. This reading is open for the product owner.
  • The frontend describeChanges.ts still reads the old change-set key form. It is fixed in the frontend PR.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments

Minor 1
  1. Specify that the added entry has an account name.
Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 5f2c34f and 90b54ae.

Files selected for processing: 19

  • api/oss/src/core/workflows/change_set.py
  • api/oss/src/core/workflows/service.py
  • api/oss/tests/pytest/unit/workflows/test_change_set.py
  • docs/design/composio-tools-rework/runtime-tools.md
  • openspec/changes/multiple-accounts-per-integration/design.md
  • openspec/changes/multiple-accounts-per-integration/specs/gateway-multi-account/spec.md
  • openspec/changes/multiple-accounts-per-integration/tasks.md
  • sdks/python/agenta/sdk/agents/adapters/harnesses.py
  • sdks/python/agenta/sdk/agents/dtos.py
  • sdks/python/agenta/sdk/agents/platform/gateway.py
  • sdks/python/agenta/sdk/agents/platform_instructions.py
  • sdks/python/agenta/sdk/agents/tools/compat.py
  • sdks/python/agenta/sdk/agents/tools/models.py
  • sdks/python/oss/tests/pytest/unit/agents/golden/run_request.gateway_connection.multi_account.json
  • sdks/python/oss/tests/pytest/unit/agents/platform/test_gateway_multi_account.py
  • sdks/python/oss/tests/pytest/unit/agents/test_harness_adapters.py
  • services/runner/src/protocol.ts
  • services/runner/src/tools/gateway-policy.ts
  • services/runner/tests/unit/gateway-multi-account.test.ts
Files skipped from review as they are similar to previous changes: 5

  • docs/design/composio-tools-rework/runtime-tools.md
  • openspec/changes/multiple-accounts-per-integration/tasks.md
  • sdks/python/agenta/sdk/agents/tools/models.py
  • services/runner/src/protocol.ts
  • services/runner/tests/unit/gateway-multi-account.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments

Outside diff 1
  1. Allow correction of account-selection refusals.
    sdks/python/agenta/sdk/agents/platform/gateway.py, lines 160–161 · 🎯 Functional Correctness · ⚡ Quick win
    For named Gmail entries, a call without account must be refused with the available names. These instructions tell the model not to change arguments after any refusal. They conflict with the account guidance and can stop a call that would succeed with account: "work".
    When with_account is true, distinguish missing or unknown account refusals from permission refusals. Permit correction of account. Keep the existing description for agents without account entries.
Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 90b54ae and 9e6b7f3.

Files selected for processing: 4

  • docs/docs/reference/agents/01-agent-configuration.mdx
  • openspec/changes/multiple-accounts-per-integration/specs/gateway-multi-account/spec.md
  • sdks/python/agenta/sdk/agents/platform/gateway.py
  • sdks/python/oss/tests/pytest/unit/agents/platform/test_gateway_multi_account.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@mmabrouk

mmabrouk commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

🤖 The AI agent says: @coderabbitai Fixed the review body item "Allow correction of account-selection refusals" in e35a41b. For an agent with account names, the run_tool description now adds one sentence: a refusal that says account is missing or not configured lists the account names, and the model calls again with one of them. Every other refusal stays final. Agents without accounts keep the old description, so their payload stays byte-identical. The multi-account golden and the design doc are updated.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments

Minor 1
  1. Handle refusals for integrations without named accounts.
Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9e6b7f3 and e35a41b.

Files selected for processing: 3

  • docs/design/composio-tools-rework/runtime-tools.md
  • sdks/python/agenta/sdk/agents/platform/gateway.py
  • sdks/python/oss/tests/pytest/unit/agents/golden/run_request.gateway_connection.multi_account.json

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

@mmabrouk mmabrouk added lgtm This PR has been approved by a maintainer merge queue In the release merge queue; an agent is landing it labels Dec 4, 2026
@coderabbitai

coderabbitai Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

Analysis chain

Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- Current revision ---'
git rev-parse HEAD
printf '%s\n' '--- Reported commit summary ---'
git show --format=fuller --stat --no-renames e35a41b 2>&1
printf '%s\n' '--- Reported commit diff ---'
git show --format= --no-ext-diff --no-renames e35a41b -- sdks/python/agenta/sdk/agents/platform/gateway.py sdks/python/oss/tests/pytest/unit/agents/golden/run_request.gateway_connection.multi_account.json docs/design/composio-tools-rework/runtime-tools.md 2>&1
printf '%s\n' '--- Gateway outline ---'
ast-grep outline sdks/python/agenta/sdk/agents/platform/gateway.py --match '_derived_tool_specs' --view expanded 2>&1
printf '%s\n' '--- Current refusal guidance and account gating ---'
rg -n -C 5 'refusal|with_account|not configured|missing' sdks/python/agenta/sdk/agents/platform/gateway.py | head -200
printf '%s\n' '--- Relevant test coverage ---'
rg -n -C 3 'refusal|derived_specs_change_only|byte.identical|multi.account' sdks/python/oss/tests/pytest/unit/agents/platform/test_gateway_connection_resolve.py sdks/python/oss/tests/pytest/unit/agents/platform/test_gateway_multi_account.py | head -180

Length of output: 13480


Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- Runner policy outline ---'
ast-grep outline services/runner/src/tools/gateway-policy.ts --items all --match 'Account|GatewayRun|unknown|missing' --view expanded
printf '%s\n' '--- Account-selection code and refusal text ---'
rg -n -C 9 'unknownAccountText|missingAccountText|no named accounts|not configured|account.*undefined' services/runner/src/tools/gateway-policy.ts
printf '%s\n' '--- Platform guidance outline ---'
ast-grep outline sdks/python/agenta/sdk/agents/platform_instructions.py --items all --match 'gateway_guidance' --view expanded
printf '%s\n' '--- Platform account guidance ---'
rg -n -C 7 'refusal|account' sdks/python/agenta/sdk/agents/platform_instructions.py | head -150
printf '%s\n' '--- Account selection test cases ---'
rg -n -C 5 'no named accounts|not configured|unknown account|missing account' services/runner/tests/unit/gateway-multi-account.test.ts | head -180

Length of output: 13448


@mmabrouk Thanks for the fix. The new guidance allows correction when the runner lists account names. The golden and design doc also reflect the change.

One case remains: if an agent has a named Gmail account and an accountless Slack integration, a call to Slack with account is refused. The runner asks the model to retry without account, but the tool description and prompt say to retry with a listed name. There is no name to list.

Please update the guidance in gateway.py Line 140 and platform_instructions.py Line 471 to cover that case, and add a mixed-integration test. I inspected the changes but did not run tests.


Learnings used

Learnt from: mmabrouk
Repo: Agenta-AI/agenta PR: 8859
File: sdks/python/agenta/sdk/agents/platform/gateway.py:603-605
Timestamp: 2026-12-04T14:37:34.489Z
Learning: Within repository "Agenta-AI/agenta", only for files matching one of ["sdks/python/agenta/sdk/agents/platform/gateway.py"]: In sdks/python/agenta/sdk/agents/platform/gateway.py, keep the derived gateway customTools stable across connection availability changes and integration-name changes within the same account-schema state. customTools contributes to the warm-session fingerprint, so availability-dependent schemas or integration names in tool descriptions can restart a warm session. Derive run_tool account support from configured entries, including entries that need setup; adding or removing the first named account can legitimately change the schema.

If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

You are interacting with an AI system.

…ut account names

The run_tool description and the prompt now say to call again without
account when the refusal says the integration has no named accounts.
The build loop step now says one gateway_connection entry per account
when the person wants several accounts of one integration.
@mmabrouk

mmabrouk commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

🤖 The AI agent says:

Review loop result for head 2d2a4ee80141a3bc15a87e7cf6da823b4d5a5aae, 1 round by the merge queue agent. The earlier records cover head 90b54ae, so this round reviewed only the commits after it (9e6b7f3, e35a41b, 2d2a4ee).

Lens Final rating
Correctness Low
Security Low

Checked:

  • The account flag on run_tool now comes from the configured entries, not the resolved ones. When every account of an integration needs setup, the schema keeps account and the runner has no entry for that integration, so it refuses the call as not connected. No call can reach another account's connection.
  • The commits after 90b54ae change no routing, no policy key and no permission check. They change model-facing text, one schema flag source and the docs.
  • The run_tool description and prompt rule now match all three runner refusal texts, including the one for an integration without account names.

Fixed: 2d2a4ee lets the account correction also cover "call without account", and the build loop step says one entry per account (the CodeRabbit outside-diff item on agenta_builtins.py).

Tests: SDK unit folder (4165 passed), runner wire-contract and gateway-multi-account tests pass.

@mmabrouk

mmabrouk commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

🤖 The AI agent says: @coderabbitai Fixed the outside-diff item "Update the build loop to permit multiple accounts" in 2d2a4ee. Step 3 of the build loop in agenta_builtins.py now says to add one gateway_connection entry per account, each with its own account, when the person wants several accounts of one integration. A single entry without account stays valid.

@mmabrouk mmabrouk mentioned this pull request Dec 4, 2026
13 tasks

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments

Major 1
  1. Do not substitute a different account after a refusal.
Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e35a41b and 2d2a4ee.

Files selected for processing: 5

  • docs/design/composio-tools-rework/runtime-tools.md
  • sdks/python/agenta/sdk/agents/adapters/agenta_builtins.py
  • sdks/python/agenta/sdk/agents/platform/gateway.py
  • sdks/python/agenta/sdk/agents/platform_instructions.py
  • sdks/python/oss/tests/pytest/unit/agents/golden/run_request.gateway_connection.multi_account.json
Files skipped from review as they are similar to previous changes: 1

  • sdks/python/agenta/sdk/agents/platform/gateway.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

@coderabbitai

coderabbitai Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

Analysis chain

Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- Revision ---'
git rev-parse HEAD
printf '%s\n' '--- Locate file ---'
fd -t f '^agenta_builtins\.py$' .
printf '%s\n' '--- File outline ---'
ast-grep outline sdks/python/agenta/sdk/agents/adapters/agenta_builtins.py --items all --view expanded
printf '%s\n' '--- Build-loop account guidance ---'
rg -n -C 10 'one entry per account|per account|several accounts|gateway_connection|build loop' sdks/python/agenta/sdk/agents/adapters/agenta_builtins.py
printf '%s\n' '--- Reported commit diff ---'
git show --format=fuller --no-ext-diff 2d2a4ee -- sdks/python/agenta/sdk/agents/adapters/agenta_builtins.py

Length of output: 17333


@mmabrouk Thanks. I verified that Step 3 now describes one entry per account, and the configuration reference permits a single entry without account.

One related summary still says “one gateway_connection entry each” for integrations in agenta_builtins.py Line 726. Please update it to match the multi-account guidance.

I did not run tests.

You are interacting with an AI system.

When the account the user meant is not listed, or the choice is not
clear, the model asks the user instead of retrying with a different
account.
@mmabrouk

mmabrouk commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

🤖 The AI agent says:

Review loop result for head 43719cc23d29c4003d5c1ee043e331ffe23521f8, round 2 by the merge queue agent. Round 1 (head 2d2a4ee) reviewed the commits after 90b54ae. Round 2 reviews only 43719cc.

Lens Final rating
Correctness Low
Security Low

Fixed in round 2: CodeRabbit found that the account correction rule let the model retry with a different listed account when the account the user meant was missing, for example when that account needs setup and was left out of the run. The run_tool description and the prompt rule now say to retry only with the account the user meant, and to ask the user when it is not listed or not clear. The runner routing and permission checks did not change.

Tests: SDK unit folder (4165 passed), runner wire-contract and gateway-multi-account tests pass.

@mmabrouk

mmabrouk commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

🤖 The AI agent says: @coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

@mmabrouk I’ll review the changes.


Learnings added

Learnt from: mmabrouk
URL: https://github.com/Agenta-AI/agenta/pull/8859

Timestamp: 2026-12-04T15:17:04.677Z
Learning: Within repository "Agenta-AI/agenta", only for files matching one of ["sdks/python/agenta/sdk/agents/platform/gateway.py","sdks/python/agenta/sdk/agents/platform_instructions.py"]: In the gateway run_tool description and platform instructions, account-selection refusal guidance must not direct the model to choose a different listed account when the user's intended account is unavailable. Retry only with the account the user intended; ask the user if that account is unclear or not listed. An account that needs setup can be absent from the resolved list.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


Learnings used

Learnt from: CR
Repo: Agenta-AI/agenta PR: 0
File: .agents/skills/review-correctness/SKILL.md:0-0
Timestamp: 2026-11-21T08:05:46.154Z
Learning: Source excerpt:
# Review a change for correctness

## Rules

- Do not charge the change for problems in code it does not touch, unless the change makes
  an existing problem reachable.
Learnt from: mmabrouk
Repo: Agenta-AI/agenta PR: 8859
File: sdks/python/agenta/sdk/agents/platform/gateway.py:603-605
Timestamp: 2026-12-04T14:37:34.489Z
Learning: Within repository "Agenta-AI/agenta", only for files matching one of ["sdks/python/agenta/sdk/agents/platform/gateway.py"]: In sdks/python/agenta/sdk/agents/platform/gateway.py, keep the derived gateway customTools stable across connection availability changes and integration-name changes within the same account-schema state. customTools contributes to the warm-session fingerprint, so availability-dependent schemas or integration names in tool descriptions can restart a warm session. Derive run_tool account support from configured entries, including entries that need setup; adding or removing the first named account can legitimately change the schema.
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@mmabrouk
mmabrouk merged commit e48dd49 into release/v0.133.1 Dec 4, 2026
71 checks passed
@mmabrouk mmabrouk removed the merge queue In the release merge queue; an agent is landing it label Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant