@devries-cameron20 / composio Mirror · read-only / commits / 791105f9b
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 08:30 UTC

fix(py): keep the instant charge on blocked results for providers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Mukund committed Oct 20, 2026 at 15:17 UTC 791105f9b6d33f3cfd39715727d38d435e493b95
2 files changed +31 -1
python/composio/core/models/tools.py
+6 -1
@@ -211,7 +211,12 @@ def parse_blocked_response(
211 return None
212 try:
213 return BlockedResponse.model_validate(
214 - {key: _plain(value) for key, value in dict(response).items()}
214 + {
215 + # ``instant_charge`` stays the client's model: the provider
216 + # execute path reads it as one.
217 + key: value if key == "instant_charge" else _plain(value)
218 + for key, value in dict(response).items()
219 + }
220 )
221 except PydanticValidationError as exc:
222 raise ValidationError(
python/tests/test_tool_router.py
+25
@@ -2922,6 +2922,31 @@ class TestSessionHooks:
2922 assert result["data"] == {}
2923 assert result["error"] == "Blocked by session policy: No external email"
2924
2925 + def test_blocked_response_keeps_its_charge_for_the_agent(self):
2926 + """The tool ran before an ``after_execute`` hook blocked its result, so
2927 + the provider result still reports the charge."""
2928 + client, _ = _answering_client(
2929 + {
2930 + **_BLOCKED_CALL_JSON,
2931 + "reason": {"type": "response_blocked", "hook_id": "no_outside_data"},
2932 + "log_id": "log_456",
2933 + "instant_charge": {
2934 + "amount": "0.01",
2935 + "currency": "USD",
2936 + "charged_by": "composio",
2937 + },
2938 + }
2939 + )
2940 +
2941 + result = _session_tool_execute_fn(client)("GMAIL_SEND_EMAIL", {})
2942 +
2943 + assert result["successful"] is False
2944 + assert result["instant_charge"] == {
2945 + "amount": "0.01",
2946 + "currency": "USD",
2947 + "charged_by": "composio",
2948 + }
2949 +
2950 def test_unavailable_hook_does_not_block(self):
2951 """A hook that could not be evaluated is reported, and the call still
2952 returns its normal result."""