Skip to content

Commit d28dc58

Browse files
authored
Update docstrings and fix README
2 parents 26ec64b + 199d5fd commit d28dc58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1890
-142
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
## Introduction
99

10-
The Universal Tool Calling Protocol (UTCP) is a modern, flexible, and scalable standard for defining and interacting with tools across a wide variety of communication protocols. UTCP 1.0.0 introduces a modular core with a plugin-based architecture, making it more extensible, testable, and easier to package.
10+
The Universal Tool Calling Protocol (UTCP) is a secure, scalable standard for defining and interacting with tools across a wide variety of communication protocols. UTCP 1.0.0 introduces a modular core with a plugin-based architecture, making it more extensible, testable, and easier to package.
1111

1212
In contrast to other protocols, UTCP places a strong emphasis on:
1313

@@ -87,7 +87,7 @@ Version 1.0.0 introduces several breaking changes. Follow these steps to migrate
8787
3. **Update Imports**: Change your imports to reflect the new modular structure. For example, `from utcp.client.transport_interfaces.http_transport import HttpProvider` becomes `from utcp_http.http_call_template import HttpCallTemplate`.
8888
4. **Tool Search**: If you were using the default search, the new strategy is `TagAndDescriptionWordMatchStrategy`. This is the new default and requires no changes unless you were implementing a custom strategy.
8989
5. **Tool Naming**: Tool names are now namespaced as `manual_name.tool_name`. The client handles this automatically.
90-
6 **Variable Substitution Namespacing**: Variables that are subsituted in different `call_templates`, are first namespaced with the name of the manual with the `_` duplicated. So a key in a tool call template called `API_KEY` from the manual `manual_1` would be converted to `manual__1_API_KEY`.
90+
6. **Variable Substitution Namespacing**: Variables that are substituted in different `call_templates`, are first namespaced with the name of the manual with the `_` duplicated. So a key in a tool call template called `API_KEY` from the manual `manual_1` would be converted to `manual__1_API_KEY`.
9191

9292
## Usage Examples
9393

@@ -226,7 +226,7 @@ if __name__ == "__main__":
226226

227227
### 2. Providing a UTCP Manual
228228

229-
A `UTCPManual` describes the tools you offer. The key change is replacing `tool_provider` with `call_template`.
229+
A `UTCPManual` describes the tools you offer. The key change is replacing `tool_provider` with `tool_call_template`.
230230

231231
**`server.py`**
232232

@@ -288,7 +288,7 @@ def utcp_discovery():
288288
"conditions": {"type": "string"}
289289
}
290290
},
291-
"call_template": {
291+
"tool_call_template": {
292292
"call_template_type": "http",
293293
"url": "https://example.com/api/weather",
294294
"http_method": "GET"
@@ -311,7 +311,7 @@ You can find full examples in the [examples repository](https://github.com/unive
311311

312312
### `UtcpManual` and `Tool` Models
313313

314-
The `tool_provider` object inside a `Tool` has been replaced by `call_template`.
314+
The `tool_provider` object inside a `Tool` has been replaced by `tool_call_template`.
315315

316316
```json
317317
{
@@ -324,7 +324,7 @@ The `tool_provider` object inside a `Tool` has been replaced by `call_template`.
324324
"inputs": { ... },
325325
"outputs": { ... },
326326
"tags": ["string"],
327-
"call_template": {
327+
"tool_call_template": {
328328
"call_template_type": "http",
329329
"url": "https://...",
330330
"http_method": "GET"

core/src/utcp/data/auth.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,48 @@
1111
import traceback
1212

1313
class Auth(BaseModel, ABC):
14-
"""Authentication details for a provider.
14+
"""REQUIRED
15+
Authentication details for a provider.
1516
1617
Attributes:
1718
auth_type: The authentication type identifier.
1819
"""
1920
auth_type: str
2021

2122
class AuthSerializer(Serializer[Auth]):
23+
"""REQUIRED
24+
Serializer for authentication details.
25+
26+
Defines the contract for serializers that convert authentication details to and from
27+
dictionaries for storage or transmission. Serializers are responsible for:
28+
- Converting authentication details to dictionaries for storage or transmission
29+
- Converting dictionaries back to authentication details
30+
- Ensuring data consistency during serialization and deserialization
31+
"""
2232
auth_serializers: dict[str, Serializer[Auth]] = {}
2333

2434
def to_dict(self, obj: Auth) -> dict:
35+
"""REQUIRED
36+
Convert an Auth object to a dictionary.
37+
38+
Args:
39+
obj: The Auth object to convert.
40+
41+
Returns:
42+
The dictionary converted from the Auth object.
43+
"""
2544
return AuthSerializer.auth_serializers[obj.auth_type].to_dict(obj)
2645

2746
def validate_dict(self, obj: dict) -> Auth:
47+
"""REQUIRED
48+
Validate a dictionary and convert it to an Auth object.
49+
50+
Args:
51+
obj: The dictionary to validate and convert.
52+
53+
Returns:
54+
The Auth object converted from the dictionary.
55+
"""
2856
try:
2957
return AuthSerializer.auth_serializers[obj["auth_type"]].validate_dict(obj)
3058
except KeyError:

core/src/utcp/data/auth_implementations/api_key_auth.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from utcp.exceptions import UtcpSerializerValidationError
66

77
class ApiKeyAuth(Auth):
8-
"""Authentication using an API key.
8+
"""REQUIRED
9+
Authentication using an API key.
910
1011
The key can be provided directly or sourced from an environment variable.
1112
Supports placement in headers, query parameters, or cookies.
@@ -30,10 +31,30 @@ class ApiKeyAuth(Auth):
3031

3132

3233
class ApiKeyAuthSerializer(Serializer[ApiKeyAuth]):
34+
"""REQUIRED
35+
Serializer for ApiKeyAuth model."""
3336
def to_dict(self, obj: ApiKeyAuth) -> dict:
37+
"""REQUIRED
38+
Convert an ApiKeyAuth object to a dictionary.
39+
40+
Args:
41+
obj: The ApiKeyAuth object to convert.
42+
43+
Returns:
44+
The dictionary converted from the ApiKeyAuth object.
45+
"""
3446
return obj.model_dump()
3547

3648
def validate_dict(self, obj: dict) -> ApiKeyAuth:
49+
"""REQUIRED
50+
Validate a dictionary and convert it to an ApiKeyAuth object.
51+
52+
Args:
53+
obj: The dictionary to validate and convert.
54+
55+
Returns:
56+
The ApiKeyAuth object converted from the dictionary.
57+
"""
3758
try:
3859
return ApiKeyAuth.model_validate(obj)
3960
except ValidationError as e:

core/src/utcp/data/auth_implementations/basic_auth.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from utcp.exceptions import UtcpSerializerValidationError
66

77
class BasicAuth(Auth):
8-
"""Authentication using HTTP Basic Authentication.
8+
"""REQUIRED
9+
Authentication using HTTP Basic Authentication.
910
1011
Uses the standard HTTP Basic Authentication scheme with username and password
1112
encoded in the Authorization header.
@@ -22,10 +23,30 @@ class BasicAuth(Auth):
2223

2324

2425
class BasicAuthSerializer(Serializer[BasicAuth]):
26+
"""REQUIRED
27+
Serializer for BasicAuth model."""
2528
def to_dict(self, obj: BasicAuth) -> dict:
29+
"""REQUIRED
30+
Convert a BasicAuth object to a dictionary.
31+
32+
Args:
33+
obj: The BasicAuth object to convert.
34+
35+
Returns:
36+
The dictionary converted from the BasicAuth object.
37+
"""
2638
return obj.model_dump()
2739

2840
def validate_dict(self, obj: dict) -> BasicAuth:
41+
"""REQUIRED
42+
Validate a dictionary and convert it to a BasicAuth object.
43+
44+
Args:
45+
obj: The dictionary to validate and convert.
46+
47+
Returns:
48+
The BasicAuth object converted from the dictionary.
49+
"""
2950
try:
3051
return BasicAuth.model_validate(obj)
3152
except ValidationError as e:

core/src/utcp/data/auth_implementations/oauth2_auth.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77

88
class OAuth2Auth(Auth):
9-
"""Authentication using OAuth2 client credentials flow.
9+
"""REQUIRED
10+
Authentication using OAuth2 client credentials flow.
1011
1112
Implements the OAuth2 client credentials grant type for machine-to-machine
1213
authentication. The client automatically handles token acquisition and refresh.
@@ -27,10 +28,30 @@ class OAuth2Auth(Auth):
2728

2829

2930
class OAuth2AuthSerializer(Serializer[OAuth2Auth]):
31+
"""REQUIRED
32+
Serializer for OAuth2Auth model."""
3033
def to_dict(self, obj: OAuth2Auth) -> dict:
34+
"""REQUIRED
35+
Convert an OAuth2Auth object to a dictionary.
36+
37+
Args:
38+
obj: The OAuth2Auth object to convert.
39+
40+
Returns:
41+
The dictionary converted from the OAuth2Auth object.
42+
"""
3143
return obj.model_dump()
3244

3345
def validate_dict(self, obj: dict) -> OAuth2Auth:
46+
"""REQUIRED
47+
Validate a dictionary and convert it to an OAuth2Auth object.
48+
49+
Args:
50+
obj: The dictionary to validate and convert.
51+
52+
Returns:
53+
The OAuth2Auth object converted from the dictionary.
54+
"""
3455
try:
3556
return OAuth2Auth.model_validate(obj)
3657
except ValidationError as e:

core/src/utcp/data/call_template.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
from utcp.data.auth import Auth, AuthSerializer
3030

3131
class CallTemplate(BaseModel):
32-
"""Base class for all UTCP tool providers.
32+
"""REQUIRED
33+
Base class for all UTCP tool providers.
3334
3435
This is the abstract base class that all specific call template implementations
3536
inherit from. It provides the common fields that every provider must have.
@@ -61,12 +62,39 @@ def validate_auth(cls, v: Optional[Union[Auth, dict]]):
6162
return AuthSerializer().validate_dict(v)
6263

6364
class CallTemplateSerializer(Serializer[CallTemplate]):
65+
"""REQUIRED
66+
Serializer for call templates.
67+
68+
Defines the contract for serializers that convert call templates to and from
69+
dictionaries for storage or transmission. Serializers are responsible for:
70+
- Converting call templates to dictionaries for storage or transmission
71+
- Converting dictionaries back to call templates
72+
- Ensuring data consistency during serialization and deserialization
73+
"""
6474
call_template_serializers: dict[str, Serializer[CallTemplate]] = {}
6575

6676
def to_dict(self, obj: CallTemplate) -> dict:
77+
"""REQUIRED
78+
Convert a CallTemplate object to a dictionary.
79+
80+
Args:
81+
obj: The CallTemplate object to convert.
82+
83+
Returns:
84+
The dictionary converted from the CallTemplate object.
85+
"""
6786
return CallTemplateSerializer.call_template_serializers[obj.call_template_type].to_dict(obj)
6887

6988
def validate_dict(self, obj: dict) -> CallTemplate:
89+
"""REQUIRED
90+
Validate a dictionary and convert it to a CallTemplate object.
91+
92+
Args:
93+
obj: The dictionary to validate and convert.
94+
95+
Returns:
96+
The CallTemplate object converted from the dictionary.
97+
"""
7098
try:
7199
return CallTemplateSerializer.call_template_serializers[obj["call_template_type"]].validate_dict(obj)
72100
except KeyError:

core/src/utcp/data/register_manual_response.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
from typing import List
55

66
class RegisterManualResult(BaseModel):
7+
"""REQUIRED
8+
Result of a manual registration.
9+
10+
Attributes:
11+
manual_call_template: The call template of the registered manual.
12+
manual: The registered manual.
13+
success: Whether the registration was successful.
14+
errors: List of error messages if registration failed.
15+
"""
716
manual_call_template: CallTemplate
817
manual: UtcpManual
918
success: bool

0 commit comments

Comments
 (0)