Skip to content

feat(extensibility): implement call_hook_agw#156

Open
yashmeet29 wants to merge 21 commits into
SAP:mainfrom
yashmeet29:callHookViaGateway
Open

feat(extensibility): implement call_hook_agw#156
yashmeet29 wants to merge 21 commits into
SAP:mainfrom
yashmeet29:callHookViaGateway

Conversation

@yashmeet29

@yashmeet29 yashmeet29 commented Jun 11, 2026

Copy link
Copy Markdown

Disclaimer: Do not include SAP-internal or customer-specific information in this PR (e.g. internal system URLs, customer names, tenant IDs, or confidential configurations). This is a public repository.

Description

Adds call_hook_agw, an async method on ExtensibilityClient that calls an n8n hook via the Agent Gateway (AGW) MCP transport, as an alternative to the existing call_hook method which uses a direct HTTP connection.

The method:

  1. Creates an AGW client for the given tenant subdomain via create_agw_client.
  2. Discovers MCP tools from the AGW, using a composite (name, server_name) key to match execute_workflow and get_execution tools on the sap.btpn8n:apiResource:ManagedN8nMcpServer:v1 server specifically.
  3. Invokes execute_workflow with the workflow ID, method, body (serialised from the optional Message payload), and headers.
  4. After checking for terminal errors in the initial execute_workflow response, always enters the get_execution poll loop.
  5. Polls get_execution every 500 ms until the execution reaches success (extracts and returns a Message from the last executed node), a terminal status, or hook.timeout seconds elapse — raising TransportError in all failure/timeout cases.

Type of Change

Please check the relevant option:

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Dependency update

How to Test

  1. Extend the Agent using the Extensibility Skill
  2. Extend the agent with pre/post hooks
  3. Call the Agent through AgentGateway (A2A)
  4. Verify the hooks were executed and the Agent response is correct

Checklist

  • I have read the Contributing Guidelines
  • I have verified that my changes solve the issue
  • I have added/updated automated tests to cover my changes
  • All tests pass locally
  • I have verified that my code follows the Code Guidelines
  • I have updated documentation (if applicable)
  • I have added type hints for all public APIs
  • My code does not contain sensitive information (credentials, tokens, etc.)
  • I have followed Conventional Commits for commit messages

Additional Notes

call_hook_agw uses Operation.EXTENSIBILITY_CALL_HOOK for telemetry — the same operation name as the existing call_hook. This is intentional reuse of a pre-existing enum value; no new telemetry operation was introduced.

Tool lookup uses a composite key (name, server_name) to avoid false matches when multiple MCP servers expose tools with the same name. The server name is sap.btpn8n:apiResource:ManagedN8nMcpServer:v1.

Two distinct terminal-status sets are used: _EXECUTE_TERMINAL_STATUSES (checked against the initial execute_workflow response, includes "unknown") and _EXECUTION_TERMINAL_STATUSES (checked during the poll loop, excludes "unknown").

11 new unit tests cover: tool-not-found for both tools, composite-key correctness (wrong server ignored, correct tool selected among duplicates), synchronous success, success after polling, terminal status from execute and from poll, timeout, AGW exception propagation, and workflow ID forwarding.

@yashmeet29 yashmeet29 requested a review from a team as a code owner June 11, 2026 07:09
@cla-assistant

cla-assistant Bot commented Jun 11, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@yashmeet29 yashmeet29 changed the title Implement call hook via Agent Gateway feat(extensibility): implement call_hook_agw Jun 22, 2026
@cassiofariasmachado

Copy link
Copy Markdown
Member

Implement callHook function via Agent Gateway

Please provide a more detailed description of this pull request using our template pull_request_template.md


_EXECUTE_WORKFLOW_TOOL_NAME = "execute_workflow"
_GET_EXECUTION_TOOL_NAME = "get_execution"
_N8N_MCP_SERVER_NAME = "sap.btpn8n:apiResource:ManagedN8nMcpServer:v1"

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.

ORD ID is dynamically discovered using SPII. As far as I know, agent should also have formation with n8n.

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.

Agent does have a formation with n8n, but other mcp servers may also be part of the formation. In that case we need to use the ORD ID to filter through the fragments.

Also this ORD ID will be constant for hooks, they are only using n8n for now

),
None,
)
if execute_tool is None:

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.

Let's breakdown in functions and organize code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

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.

4 participants