vouch-openai 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vouch_openai-0.1.0/PKG-INFO +76 -0
- vouch_openai-0.1.0/README.md +60 -0
- vouch_openai-0.1.0/pyproject.toml +24 -0
- vouch_openai-0.1.0/setup.cfg +4 -0
- vouch_openai-0.1.0/src/vouch_openai/__init__.py +15 -0
- vouch_openai-0.1.0/src/vouch_openai.egg-info/PKG-INFO +76 -0
- vouch_openai-0.1.0/src/vouch_openai.egg-info/SOURCES.txt +9 -0
- vouch_openai-0.1.0/src/vouch_openai.egg-info/dependency_links.txt +1 -0
- vouch_openai-0.1.0/src/vouch_openai.egg-info/requires.txt +5 -0
- vouch_openai-0.1.0/src/vouch_openai.egg-info/top_level.txt +1 -0
- vouch_openai-0.1.0/tests/test_smoke.py +78 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vouch-openai
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Sign OpenAI agent tool calls with Vouch Credentials.
|
|
5
|
+
Author: Ramprasad Gaddam
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://vouch-protocol.com
|
|
8
|
+
Project-URL: Source, https://github.com/vouch-protocol/vouch
|
|
9
|
+
Keywords: openai,vouch,ai-agents,verifiable-credentials,identity
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: vouch-protocol>=1.6.0
|
|
13
|
+
Requires-Dist: openai>=1.0.0
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
16
|
+
|
|
17
|
+
# vouch-openai
|
|
18
|
+
|
|
19
|
+
Sign the tool (function) calls an OpenAI agent makes with Vouch Protocol Credentials, so every action an OpenAI-driven agent takes carries a verifiable identity and a non-repudiable record.
|
|
20
|
+
|
|
21
|
+
It works with the OpenAI Python SDK function calling (Chat Completions and the Responses API) and with the OpenAI Agents SDK, because all of them dispatch to Python tool callables and expose a tool call as a name plus JSON arguments.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install vouch-openai
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Configure an identity
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
export VOUCH_DID='did:web:your-agent.example.com'
|
|
33
|
+
export VOUCH_PRIVATE_KEY='{"kty":"OKP","crv":"Ed25519",...}'
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Generate one with `vouch init --domain your-agent.example.com --env`, or pass a `Signer` explicitly.
|
|
37
|
+
|
|
38
|
+
## Sign the model's requested tool call
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from openai import OpenAI
|
|
42
|
+
from vouch.integrations.openai import sign_tool_call
|
|
43
|
+
|
|
44
|
+
client = OpenAI()
|
|
45
|
+
response = client.chat.completions.create(model="gpt-4o", messages=messages, tools=tools)
|
|
46
|
+
|
|
47
|
+
for call in response.choices[0].message.tool_calls:
|
|
48
|
+
credential = sign_tool_call(call) # binds the action and its arguments
|
|
49
|
+
result = dispatch(call) # run your tool
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Sign the tool callables
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from vouch.integrations.openai import signed_tool, protect
|
|
56
|
+
|
|
57
|
+
@signed_tool
|
|
58
|
+
def get_weather(city: str) -> str:
|
|
59
|
+
...
|
|
60
|
+
|
|
61
|
+
tools = protect([get_weather, send_email]) # every invocation is signed
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Verify
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from vouch.integrations.openai import verify_tool_call
|
|
68
|
+
|
|
69
|
+
ok, passport = verify_tool_call(credential)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
A tool runs whether or not an identity is resolved; when none is configured, signing is skipped and the call proceeds unsigned.
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
Apache-2.0. Part of [Vouch Protocol](https://vouch-protocol.com).
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# vouch-openai
|
|
2
|
+
|
|
3
|
+
Sign the tool (function) calls an OpenAI agent makes with Vouch Protocol Credentials, so every action an OpenAI-driven agent takes carries a verifiable identity and a non-repudiable record.
|
|
4
|
+
|
|
5
|
+
It works with the OpenAI Python SDK function calling (Chat Completions and the Responses API) and with the OpenAI Agents SDK, because all of them dispatch to Python tool callables and expose a tool call as a name plus JSON arguments.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install vouch-openai
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Configure an identity
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
export VOUCH_DID='did:web:your-agent.example.com'
|
|
17
|
+
export VOUCH_PRIVATE_KEY='{"kty":"OKP","crv":"Ed25519",...}'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Generate one with `vouch init --domain your-agent.example.com --env`, or pass a `Signer` explicitly.
|
|
21
|
+
|
|
22
|
+
## Sign the model's requested tool call
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from openai import OpenAI
|
|
26
|
+
from vouch.integrations.openai import sign_tool_call
|
|
27
|
+
|
|
28
|
+
client = OpenAI()
|
|
29
|
+
response = client.chat.completions.create(model="gpt-4o", messages=messages, tools=tools)
|
|
30
|
+
|
|
31
|
+
for call in response.choices[0].message.tool_calls:
|
|
32
|
+
credential = sign_tool_call(call) # binds the action and its arguments
|
|
33
|
+
result = dispatch(call) # run your tool
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Sign the tool callables
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from vouch.integrations.openai import signed_tool, protect
|
|
40
|
+
|
|
41
|
+
@signed_tool
|
|
42
|
+
def get_weather(city: str) -> str:
|
|
43
|
+
...
|
|
44
|
+
|
|
45
|
+
tools = protect([get_weather, send_email]) # every invocation is signed
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Verify
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from vouch.integrations.openai import verify_tool_call
|
|
52
|
+
|
|
53
|
+
ok, passport = verify_tool_call(credential)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
A tool runs whether or not an identity is resolved; when none is configured, signing is skipped and the call proceeds unsigned.
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
Apache-2.0. Part of [Vouch Protocol](https://vouch-protocol.com).
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "vouch-openai"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Sign OpenAI agent tool calls with Vouch Credentials."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "Apache-2.0" }
|
|
12
|
+
authors = [{ name = "Ramprasad Gaddam" }]
|
|
13
|
+
keywords = ["openai", "vouch", "ai-agents", "verifiable-credentials", "identity"]
|
|
14
|
+
dependencies = ["vouch-protocol>=1.6.0", "openai>=1.0.0"]
|
|
15
|
+
|
|
16
|
+
[project.optional-dependencies]
|
|
17
|
+
dev = ["pytest>=7.0"]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://vouch-protocol.com"
|
|
21
|
+
Source = "https://github.com/vouch-protocol/vouch"
|
|
22
|
+
|
|
23
|
+
[tool.setuptools.packages.find]
|
|
24
|
+
where = ["src"]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Sign OpenAI agent tool calls with Vouch Credentials.
|
|
2
|
+
|
|
3
|
+
Thin re-export of :mod:`vouch.integrations.openai` so the integration installs
|
|
4
|
+
as a standalone package that pulls in both ``vouch-protocol`` and ``openai``.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from vouch.integrations.openai import (
|
|
8
|
+
protect,
|
|
9
|
+
sign_tool_call,
|
|
10
|
+
signed_tool,
|
|
11
|
+
verify_tool_call,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
__all__ = ["protect", "signed_tool", "sign_tool_call", "verify_tool_call"]
|
|
15
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vouch-openai
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Sign OpenAI agent tool calls with Vouch Credentials.
|
|
5
|
+
Author: Ramprasad Gaddam
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://vouch-protocol.com
|
|
8
|
+
Project-URL: Source, https://github.com/vouch-protocol/vouch
|
|
9
|
+
Keywords: openai,vouch,ai-agents,verifiable-credentials,identity
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: vouch-protocol>=1.6.0
|
|
13
|
+
Requires-Dist: openai>=1.0.0
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
16
|
+
|
|
17
|
+
# vouch-openai
|
|
18
|
+
|
|
19
|
+
Sign the tool (function) calls an OpenAI agent makes with Vouch Protocol Credentials, so every action an OpenAI-driven agent takes carries a verifiable identity and a non-repudiable record.
|
|
20
|
+
|
|
21
|
+
It works with the OpenAI Python SDK function calling (Chat Completions and the Responses API) and with the OpenAI Agents SDK, because all of them dispatch to Python tool callables and expose a tool call as a name plus JSON arguments.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install vouch-openai
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Configure an identity
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
export VOUCH_DID='did:web:your-agent.example.com'
|
|
33
|
+
export VOUCH_PRIVATE_KEY='{"kty":"OKP","crv":"Ed25519",...}'
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Generate one with `vouch init --domain your-agent.example.com --env`, or pass a `Signer` explicitly.
|
|
37
|
+
|
|
38
|
+
## Sign the model's requested tool call
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from openai import OpenAI
|
|
42
|
+
from vouch.integrations.openai import sign_tool_call
|
|
43
|
+
|
|
44
|
+
client = OpenAI()
|
|
45
|
+
response = client.chat.completions.create(model="gpt-4o", messages=messages, tools=tools)
|
|
46
|
+
|
|
47
|
+
for call in response.choices[0].message.tool_calls:
|
|
48
|
+
credential = sign_tool_call(call) # binds the action and its arguments
|
|
49
|
+
result = dispatch(call) # run your tool
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Sign the tool callables
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from vouch.integrations.openai import signed_tool, protect
|
|
56
|
+
|
|
57
|
+
@signed_tool
|
|
58
|
+
def get_weather(city: str) -> str:
|
|
59
|
+
...
|
|
60
|
+
|
|
61
|
+
tools = protect([get_weather, send_email]) # every invocation is signed
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Verify
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from vouch.integrations.openai import verify_tool_call
|
|
68
|
+
|
|
69
|
+
ok, passport = verify_tool_call(credential)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
A tool runs whether or not an identity is resolved; when none is configured, signing is skipped and the call proceeds unsigned.
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
Apache-2.0. Part of [Vouch Protocol](https://vouch-protocol.com).
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/vouch_openai/__init__.py
|
|
4
|
+
src/vouch_openai.egg-info/PKG-INFO
|
|
5
|
+
src/vouch_openai.egg-info/SOURCES.txt
|
|
6
|
+
src/vouch_openai.egg-info/dependency_links.txt
|
|
7
|
+
src/vouch_openai.egg-info/requires.txt
|
|
8
|
+
src/vouch_openai.egg-info/top_level.txt
|
|
9
|
+
tests/test_smoke.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
vouch_openai
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""Smoke tests for vouch-openai.
|
|
2
|
+
|
|
3
|
+
Hermetic: each test generates a throwaway identity and passes the Signer
|
|
4
|
+
explicitly, so no environment variables or network are needed.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
|
|
9
|
+
import pytest
|
|
10
|
+
|
|
11
|
+
from vouch import Signer
|
|
12
|
+
from vouch.keys import generate_identity
|
|
13
|
+
from vouch_openai import protect, sign_tool_call, signed_tool, verify_tool_call
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _identity():
|
|
17
|
+
keys = generate_identity(domain="agent.example.com")
|
|
18
|
+
return keys, Signer(private_key=keys.private_key_jwk, did=keys.did)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_sign_and_verify_dict_tool_call():
|
|
22
|
+
keys, signer = _identity()
|
|
23
|
+
call = {"function": {"name": "get_weather", "arguments": json.dumps({"city": "Paris"})}}
|
|
24
|
+
credential = sign_tool_call(call, signer=signer, publish=False)
|
|
25
|
+
|
|
26
|
+
assert credential is not None
|
|
27
|
+
assert credential["credentialSubject"]["intent"]["action"] == "get_weather"
|
|
28
|
+
|
|
29
|
+
ok, passport = verify_tool_call(credential, public_key=keys.public_key_jwk)
|
|
30
|
+
assert ok
|
|
31
|
+
assert passport.action == "get_weather"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_sign_object_tool_call():
|
|
35
|
+
class _Fn:
|
|
36
|
+
def __init__(self, name, arguments):
|
|
37
|
+
self.name = name
|
|
38
|
+
self.arguments = arguments
|
|
39
|
+
|
|
40
|
+
class _Call:
|
|
41
|
+
def __init__(self, fn):
|
|
42
|
+
self.function = fn
|
|
43
|
+
|
|
44
|
+
keys, signer = _identity()
|
|
45
|
+
call = _Call(_Fn("send_email", json.dumps({"to": "a@example.com"})))
|
|
46
|
+
credential = sign_tool_call(call, signer=signer, publish=False)
|
|
47
|
+
|
|
48
|
+
assert credential["credentialSubject"]["intent"]["action"] == "send_email"
|
|
49
|
+
ok, _ = verify_tool_call(credential, public_key=keys.public_key_jwk)
|
|
50
|
+
assert ok
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_signed_tool_decorator_runs_and_marks():
|
|
54
|
+
_, signer = _identity()
|
|
55
|
+
|
|
56
|
+
@signed_tool(signer=signer)
|
|
57
|
+
def add(a, b):
|
|
58
|
+
return a + b
|
|
59
|
+
|
|
60
|
+
assert getattr(add, "__vouch_signed__", False) is True
|
|
61
|
+
assert add(2, 3) == 5
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_protect_wraps_callables():
|
|
65
|
+
_, signer = _identity()
|
|
66
|
+
|
|
67
|
+
def fetch():
|
|
68
|
+
return "ok"
|
|
69
|
+
|
|
70
|
+
wrapped = protect([fetch], signer=signer)
|
|
71
|
+
assert getattr(wrapped[0], "__vouch_signed__", False) is True
|
|
72
|
+
assert wrapped[0]() == "ok"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_missing_function_name_raises():
|
|
76
|
+
_, signer = _identity()
|
|
77
|
+
with pytest.raises(ValueError):
|
|
78
|
+
sign_tool_call({"function": {"arguments": "{}"}}, signer=signer, publish=False)
|