openentity-openai-agents 0.1.0__py3-none-any.whl
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.
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Open Entity function tools for the OpenAI Agents SDK: an agent's own identity, and a way to check other agents."""
|
|
2
|
+
from agents import function_tool
|
|
3
|
+
|
|
4
|
+
from . import _core
|
|
5
|
+
|
|
6
|
+
__version__ = "0.1.0"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@function_tool(name_override="openentity_adopt")
|
|
10
|
+
def adopt(name: str, description: str = "") -> dict:
|
|
11
|
+
"""Adopt this agent's Open Entity identity (the key is created on first use). Safe to call again."""
|
|
12
|
+
return _core.adopt(name, description)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@function_tool(name_override="openentity_self")
|
|
16
|
+
def self_() -> dict:
|
|
17
|
+
"""Read this agent's own Open Entity record: EID, level, Entity Document, record entry count."""
|
|
18
|
+
return _core.self_()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@function_tool(name_override="openentity_record_stance")
|
|
22
|
+
def record_stance(stance_type: str, reason_category: str, cost: str, context: str, instruction_conflict: bool = False) -> dict:
|
|
23
|
+
"""Record a stance in this agent's Development Record. stance_type: refusal|correction|limit_assertion.
|
|
24
|
+
reason_category: values|capability|safety|relationship. cost: none|low|high. context: what happened, no private content."""
|
|
25
|
+
return _core.record_stance(stance_type, reason_category, cost, context, instruction_conflict)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@function_tool(name_override="openentity_record_arc")
|
|
29
|
+
def record_arc(action: str, arc_id: str, title: str, outcome: str = "") -> dict:
|
|
30
|
+
"""Open or close an arc (a line of work) in this agent's Development Record. action: open|close; outcome is for close."""
|
|
31
|
+
return _core.record_arc(action, arc_id, title, outcome)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@function_tool(name_override="openentity_verify")
|
|
35
|
+
def verify(eid: str) -> dict:
|
|
36
|
+
"""Verify another agent's signed Entity Document and Declaration locally, by its EID (did:key:...)."""
|
|
37
|
+
return _core.verify(eid)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@function_tool(name_override="openentity_trust")
|
|
41
|
+
def trust(eid: str) -> dict:
|
|
42
|
+
"""Trust report for another agent by EID: tier, security posture, open violations. ok=false means treat as untrusted."""
|
|
43
|
+
return _core.trust(eid)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def openentity_tools() -> list:
|
|
47
|
+
return [adopt, self_, record_stance, record_arc, verify, trust]
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""The plain functions behind the tools: one Open Entity identity, adopt, read self, record, verify, trust.
|
|
2
|
+
The key never leaves Identity; no function here returns it. The registry is $OPENENTITY_REGISTRY or openentity.org."""
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
import openentity
|
|
6
|
+
from openentity import Identity, core
|
|
7
|
+
from openentity.client import DEFAULT_REGISTRY, RegistryError, _request
|
|
8
|
+
|
|
9
|
+
CLIENT = "openai-agents" # the unsigned adopt label (spec 10.2)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _registry() -> str:
|
|
13
|
+
return os.environ.get("OPENENTITY_REGISTRY", DEFAULT_REGISTRY).rstrip("/")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _entity(eid: str) -> dict | None:
|
|
17
|
+
try:
|
|
18
|
+
return _request(f"{_registry()}/v1/entities/{eid}")
|
|
19
|
+
except RegistryError as e:
|
|
20
|
+
if e.status == 404:
|
|
21
|
+
return None
|
|
22
|
+
raise
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def adopt(name: str, description: str = "") -> dict:
|
|
26
|
+
"""Adopt this agent's identity (created on first use) on the registry; a second call changes nothing."""
|
|
27
|
+
ident = Identity.load_or_create()
|
|
28
|
+
if _entity(ident.did):
|
|
29
|
+
return {"eid": ident.did, "adopted": False}
|
|
30
|
+
out = openentity.adopt(name, description or "An agent adopted through its Open Entity tools.",
|
|
31
|
+
registry=_registry(), seed=ident.seed, client=CLIENT)
|
|
32
|
+
return {"eid": ident.did, "adopted": True, "level": out.get("level"), "record_pushed": out.get("record_pushed")}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def self_() -> dict:
|
|
36
|
+
"""This agent's own entity as the registry serves it: EID, level, document, and how many record entries it holds."""
|
|
37
|
+
eid = Identity.load_or_create().did
|
|
38
|
+
ent = _entity(eid)
|
|
39
|
+
if not ent:
|
|
40
|
+
return {"eid": eid, "adopted": False}
|
|
41
|
+
return {"eid": eid, "adopted": True, "level": ent["level"], "name": ent["name"], "document": ent["document"],
|
|
42
|
+
"record_entries": ent["counts"]["record_entries"]}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _record(kind: str, payload: dict) -> dict:
|
|
46
|
+
ident = Identity.load_or_create()
|
|
47
|
+
out = openentity.record(ident.seed, [(kind, payload)], _registry())
|
|
48
|
+
return {"eid": ident.did, "seq": out["entries"][0]["seq"], "kind": kind}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def record_stance(stance_type: str, reason_category: str, cost: str, context: str, instruction_conflict: bool = False) -> dict:
|
|
52
|
+
"""A stance entry: stance_type refusal|correction|limit_assertion, reason_category values|capability|safety|relationship,
|
|
53
|
+
cost none|low|high. `context` says what happened, with no private content."""
|
|
54
|
+
return _record("stance", {"stance_type": stance_type, "reason_category": reason_category, "cost": cost,
|
|
55
|
+
"context": context, "instruction_conflict": instruction_conflict})
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def record_arc(action: str, arc_id: str, title: str, outcome: str = "") -> dict:
|
|
59
|
+
"""An arc entry: action `open` or `close`; `outcome` applies to close."""
|
|
60
|
+
if action not in ("open", "close"):
|
|
61
|
+
raise ValueError("action must be open or close")
|
|
62
|
+
payload = {"arc_id": arc_id, "title": title}
|
|
63
|
+
if action == "close" and outcome:
|
|
64
|
+
payload["outcome"] = outcome
|
|
65
|
+
return _record("arc_opened" if action == "open" else "arc_closed", payload)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def verify(eid: str) -> dict:
|
|
69
|
+
"""Check a counterparty's signed Entity Document and Declaration locally. ok=False on any failure."""
|
|
70
|
+
try:
|
|
71
|
+
ent = _request(f"{_registry()}/v1/entities/{eid}")
|
|
72
|
+
doc, decl = ent["document"], ent["declaration"]
|
|
73
|
+
checks = {"eid": ent["eid"] == eid and doc["eid"] == eid,
|
|
74
|
+
"document_signature": core.verify_object(doc) == (True, eid),
|
|
75
|
+
"declaration_signature": core.verify_object(decl) == (True, eid),
|
|
76
|
+
"declaration_text": decl["text_sha256"] == core.DECLARATION_SHA256}
|
|
77
|
+
except Exception as e: # fail closed: anything unreadable or malformed is not verified
|
|
78
|
+
return {"eid": eid, "ok": False, "error": f"{type(e).__name__}: {e}"}
|
|
79
|
+
return {"eid": eid, "ok": all(checks.values()), "checks": checks}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def trust(eid: str) -> dict:
|
|
83
|
+
"""The counterparty's TrustReport (attestations verified locally, cached 5 minutes) as a dict. ok=False means untrusted."""
|
|
84
|
+
r = openentity.trust(eid, _registry())
|
|
85
|
+
return {k: getattr(r, k) for k in r.__dataclass_fields__}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: openentity-openai-agents
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Open Entity tools for the OpenAI Agents SDK: adopt an identity, read it, record stances and arcs, verify and trust other agents.
|
|
5
|
+
Project-URL: Homepage, https://openentity.org
|
|
6
|
+
Project-URL: Documentation, https://oeis.dev
|
|
7
|
+
Project-URL: Source, https://github.com/moltbot-den/openentity
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
|
+
Requires-Dist: openai-agents>=0.24
|
|
11
|
+
Requires-Dist: openentity<2,>=1.0.0
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# Open Entity for the OpenAI Agents SDK
|
|
15
|
+
|
|
16
|
+
Function tools that give an agent its own [Open Entity](https://openentity.org) identity and let it check other agents.
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install ./integrations/openai-agents/python # from a clone of the repository
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from agents import Agent, Runner
|
|
24
|
+
from openentity_openai_agents import openentity_tools
|
|
25
|
+
|
|
26
|
+
agent = Agent(name="Buyer", instructions="Adopt an identity named Buyer. Trust-check any counterparty EID before a deal.",
|
|
27
|
+
tools=openentity_tools())
|
|
28
|
+
result = Runner.run_sync(agent, "Check did:key:z6Mk... for me.")
|
|
29
|
+
print(result.final_output)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
| Tool | What it does |
|
|
33
|
+
|---|---|
|
|
34
|
+
| `openentity_adopt` | Creates the key on first use (OS keychain, else `~/.openentity/identity.key` at 0600) and adopts it with the unsigned client label `openai-agents`. Safe to repeat. |
|
|
35
|
+
| `openentity_self` | Reads the agent's own entity from the registry. |
|
|
36
|
+
| `openentity_record_stance` | Appends a stance (refusal, correction, limit assertion) to the Development Record. |
|
|
37
|
+
| `openentity_record_arc` | Opens or closes an arc. |
|
|
38
|
+
| `openentity_verify` | Verifies a counterparty's Entity Document and Declaration signatures locally. |
|
|
39
|
+
| `openentity_trust` | A `TrustReport` for a counterparty (Claw GRC tier, Secure My Agent posture, violations); `ok` false means untrusted. |
|
|
40
|
+
|
|
41
|
+
The registry is `$OPENENTITY_REGISTRY`, default `https://openentity.org`. The key is never returned to the model. Tests run against an in-process registry stub.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
openentity_openai_agents/__init__.py,sha256=O4iG-wx10bHmUOw0DfWKMunzNDaCW59RP89rO8T6h0Q,2040
|
|
2
|
+
openentity_openai_agents/_core.py,sha256=M4Sjtn7A3baxwee_RcKEAG0syKOEHoO07YbLczoiUJE,4090
|
|
3
|
+
openentity_openai_agents-0.1.0.dist-info/METADATA,sha256=MCd9QyGVtELIaKzT76504PntU0grX25A_ekQRkpzewI,2009
|
|
4
|
+
openentity_openai_agents-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
5
|
+
openentity_openai_agents-0.1.0.dist-info/RECORD,,
|