-
Notifications
You must be signed in to change notification settings - Fork 552
feat(agent): resolve typed tools through the service #4764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
mmabrouk
wants to merge
1
commit into
feat/sdk-local-tools-contracts
from
feat/sdk-local-tools-service
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from types import SimpleNamespace | ||
| from uuid import uuid4 | ||
|
|
||
| import pytest | ||
| from pydantic import ValidationError | ||
|
|
||
| from agenta.sdk.agents.tools import BuiltinToolConfig, GatewayToolConfig | ||
|
|
||
| from oss.src.apis.fastapi.tools.models import ToolResolveRequest | ||
| from oss.src.core.tools.dtos import AgentBuiltinTool, AgentComposioTool | ||
| from oss.src.core.tools.service import ToolsService | ||
|
|
||
|
|
||
| def test_api_reuses_sdk_tool_config_classes(): | ||
| assert AgentBuiltinTool is BuiltinToolConfig | ||
| assert AgentComposioTool is GatewayToolConfig | ||
|
|
||
|
|
||
| def test_resolve_request_coerces_legacy_composio_shape(): | ||
| request = ToolResolveRequest( | ||
| tools=[ | ||
| "read", | ||
| { | ||
| "type": "composio", | ||
| "integration": "github", | ||
| "action": "GET_USER", | ||
| "connection": "c1", | ||
| }, | ||
| ] | ||
| ) | ||
| assert isinstance(request.tools[0], BuiltinToolConfig) | ||
| assert isinstance(request.tools[1], GatewayToolConfig) | ||
|
|
||
|
|
||
| def test_resolve_request_rejects_non_gateway_runtime_tools(): | ||
| with pytest.raises(ValidationError, match="only builtin and gateway"): | ||
| ToolResolveRequest( | ||
| tools=[ | ||
| { | ||
| "type": "code", | ||
| "name": "calc", | ||
| "script": "...", | ||
| } | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| async def test_api_resolution_returns_stable_call_reference(monkeypatch): | ||
| service = object.__new__(ToolsService) | ||
|
|
||
| async def _connection(**_kwargs): | ||
| return object() | ||
|
|
||
| async def _action(**_kwargs): | ||
| return SimpleNamespace( | ||
| description="Get user", | ||
| schemas=SimpleNamespace( | ||
| inputs={"type": "object", "properties": {}}, | ||
| ), | ||
| ) | ||
|
|
||
| monkeypatch.setattr(service, "resolve_connection_by_slug", _connection) | ||
| monkeypatch.setattr(service, "get_action", _action) | ||
|
|
||
| result = await service.resolve_agent_tools( | ||
| project_id=uuid4(), | ||
| tools=[ | ||
| BuiltinToolConfig(name="read"), | ||
| GatewayToolConfig( | ||
| integration="github", | ||
| action="GET_USER", | ||
| connection="c1", | ||
| ), | ||
| ], | ||
| ) | ||
| assert result.builtins == ["read"] | ||
| assert result.custom[0].call_ref == "tools.composio.github.GET_USER.c1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This coercion is what keeps /tools/resolve the gateway-only endpoint: it runs the shared coerce_tool_configs and rejects anything other than builtin or gateway, so code/client/MCP tools cannot leak into this path.