gts-agency-python-sdk 0.0.1__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.
Files changed (66) hide show
  1. agency_sdk/__init__.py +0 -0
  2. agency_sdk/auth_hooks.py +55 -0
  3. agency_sdk/client.py +212 -0
  4. agency_sdk/credentials.py +54 -0
  5. agency_sdk/delegates/__init__.py +0 -0
  6. agency_sdk/delegates/annotations_client.py +495 -0
  7. agency_sdk/delegates/annotations_dto.py +200 -0
  8. agency_sdk/delegates/base_client.py +126 -0
  9. agency_sdk/delegates/datasets_client.py +109 -0
  10. agency_sdk/delegates/datasets_dto.py +81 -0
  11. agency_sdk/delegates/datasource_client.py +44 -0
  12. agency_sdk/delegates/datasource_dto.py +107 -0
  13. agency_sdk/delegates/files_client.py +184 -0
  14. agency_sdk/delegates/files_dto.py +36 -0
  15. agency_sdk/delegates/gateway_client.py +81 -0
  16. agency_sdk/delegates/gateway_dto.py +37 -0
  17. agency_sdk/delegates/ontology_client.py +203 -0
  18. agency_sdk/delegates/ontology_dto.py +221 -0
  19. agency_sdk/delegates/prompts_client.py +56 -0
  20. agency_sdk/delegates/rules_client.py +33 -0
  21. agency_sdk/delegates/rules_dto.py +108 -0
  22. agency_sdk/delegates/session_client.py +95 -0
  23. agency_sdk/delegates/session_dto.py +94 -0
  24. agency_sdk/delegates/session_templates_client.py +23 -0
  25. agency_sdk/delegates/session_templates_dto.py +27 -0
  26. agency_sdk/delegates/session_vault_client.py +135 -0
  27. agency_sdk/delegates/session_vault_dto.py +75 -0
  28. agency_sdk/delegates/work_queue_client.py +230 -0
  29. agency_sdk/delegates/work_queue_dto.py +127 -0
  30. agency_sdk/domain.py +140 -0
  31. agency_sdk/observability/__init__.py +60 -0
  32. agency_sdk/observability/auth.py +15 -0
  33. agency_sdk/observability/bootstrap.py +344 -0
  34. agency_sdk/test/__init__.py +0 -0
  35. agency_sdk/test/conftest.py +106 -0
  36. agency_sdk/test/test_annotations_client.py +599 -0
  37. agency_sdk/test/test_annotations_dto.py +299 -0
  38. agency_sdk/test/test_base_client.py +153 -0
  39. agency_sdk/test/test_client_facade.py +105 -0
  40. agency_sdk/test/test_credentials.py +67 -0
  41. agency_sdk/test/test_files_client.py +264 -0
  42. agency_sdk/test/test_files_dto.py +93 -0
  43. agency_sdk/test/test_gateway_dto.py +70 -0
  44. agency_sdk/test/test_gateway_facade.py +229 -0
  45. agency_sdk/test/test_gateway_openai.py +76 -0
  46. agency_sdk/test/test_observability_auth.py +125 -0
  47. agency_sdk/test/test_observability_facade_threadsafety.py +50 -0
  48. agency_sdk/test/test_observability_langfuse.py +76 -0
  49. agency_sdk/test/test_observability_packaging.py +78 -0
  50. agency_sdk/test/test_observability_pipeline.py +246 -0
  51. agency_sdk/test/test_ontology_client.py +152 -0
  52. agency_sdk/test/test_ontology_dto.py +158 -0
  53. agency_sdk/test/test_session_client.py +128 -0
  54. agency_sdk/test/test_session_dto.py +75 -0
  55. agency_sdk/test/test_session_templates_client.py +36 -0
  56. agency_sdk/test/test_session_templates_dto.py +45 -0
  57. agency_sdk/test/test_session_vault_client.py +151 -0
  58. agency_sdk/test/test_session_vault_dto.py +27 -0
  59. agency_sdk/test/test_stub_requests.py +39 -0
  60. agency_sdk/test/test_work_queue_client.py +388 -0
  61. agency_sdk/test/test_work_queue_dto.py +233 -0
  62. gts_agency_python_sdk-0.0.1.dist-info/METADATA +221 -0
  63. gts_agency_python_sdk-0.0.1.dist-info/RECORD +66 -0
  64. gts_agency_python_sdk-0.0.1.dist-info/WHEEL +5 -0
  65. gts_agency_python_sdk-0.0.1.dist-info/licenses/LICENSE +201 -0
  66. gts_agency_python_sdk-0.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,81 @@
1
+ """OpenAI-client factory for the org's deployed agentgateway.
2
+
3
+ ``AgencyGatewayClient`` is not itself an HTTP client — it wires the gateway's own
4
+ Cloud Run host (never the control-plane ``base_url``), the shared rotating m2m
5
+ JWT, and the ``x-org`` routing header into standard official ``openai`` clients
6
+ and hands them back. Consumers use the returned ``openai.OpenAI`` /
7
+ ``openai.AsyncOpenAI`` for the full OpenAI surface (completions, streaming,
8
+ tools, structured outputs, retries, async).
9
+
10
+ Auth contract (live-validated, design §10): the shared ``CredentialsSupplier``
11
+ JWT as ``Authorization: Bearer`` — stamped fresh per request by an httpx auth
12
+ hook so a long-running client never sends an expired token — plus
13
+ ``x-org: <org id>`` (lowercase header, decimal-string value). Missing Bearer →
14
+ 401, missing/wrong ``x-org`` → 403 (``openai`` raises ``APIStatusError``).
15
+ """
16
+
17
+ from typing import TYPE_CHECKING, Any
18
+
19
+ from agency_sdk.credentials import CredentialsSupplier
20
+
21
+ if TYPE_CHECKING:
22
+ import openai
23
+
24
+
25
+ class AgencyGatewayClient:
26
+ """Factory for official ``openai`` clients routed through the org's agentgateway."""
27
+
28
+ def __init__(self, token_supplier: CredentialsSupplier, gateway_base_url: str, org_id: str):
29
+ self.gateway_base_url = gateway_base_url.rstrip("/")
30
+ self.token_supplier = token_supplier
31
+ self.org_id = org_id # org scoping is the x-org header, not a query param
32
+
33
+ def openai_client(self, **kwargs: Any) -> "openai.OpenAI":
34
+ """Build a standard ``openai.OpenAI`` client wired to this gateway.
35
+
36
+ The returned client is plain openai SDK — streaming, tool calling,
37
+ structured outputs, retries all work as documented upstream — with the
38
+ gateway plumbing pre-wired: ``base_url`` on the gateway host (``/v1``),
39
+ the ``x-org`` routing header, and an httpx auth hook that stamps a fresh
40
+ rotating bearer on every request (the construction-time ``api_key`` is a
41
+ placeholder the hook overrides). Extra ``kwargs`` (``max_retries``,
42
+ ``timeout``, ...) pass through to ``openai.OpenAI`` — except the four
43
+ this helper wires itself (``base_url``, ``api_key``, ``default_headers``,
44
+ ``http_client``); passing those raises ``TypeError``, so build your own
45
+ client (see ``docs/gateway.md``) if you need to control them.
46
+
47
+ Each call returns a new client; the caller owns its lifecycle.
48
+ """
49
+ import httpx
50
+ import openai
51
+
52
+ return openai.OpenAI(
53
+ base_url=f"{self.gateway_base_url}/v1",
54
+ api_key="unused-auth-via-httpx-hook", # placeholder; the hook overrides per request
55
+ default_headers={"x-org": self.org_id},
56
+ http_client=httpx.Client(auth=self._httpx_bearer_auth()),
57
+ **kwargs,
58
+ )
59
+
60
+ def async_openai_client(self, **kwargs: Any) -> "openai.AsyncOpenAI":
61
+ """Async variant of :meth:`openai_client` (``openai.AsyncOpenAI``).
62
+
63
+ Note: the bearer re-mint inside the auth hook is a synchronous (cheap,
64
+ cached) call; it blocks the event loop only on the periodic refresh.
65
+ """
66
+ import httpx
67
+ import openai
68
+
69
+ return openai.AsyncOpenAI(
70
+ base_url=f"{self.gateway_base_url}/v1",
71
+ api_key="unused-auth-via-httpx-hook", # placeholder; the hook overrides per request
72
+ default_headers={"x-org": self.org_id},
73
+ http_client=httpx.AsyncClient(auth=self._httpx_bearer_auth()),
74
+ **kwargs,
75
+ )
76
+
77
+ def _httpx_bearer_auth(self) -> Any:
78
+ """Per-request rotating-bearer httpx auth (shared core hook)."""
79
+ from agency_sdk.auth_hooks import make_httpx_bearer_auth
80
+
81
+ return make_httpx_bearer_auth(self.token_supplier.bearer_token)
@@ -0,0 +1,37 @@
1
+ """DTOs for agent gateway URL discovery.
2
+
3
+ Chat request/response modeling lives in the official ``openai`` SDK — the SDK's
4
+ gateway capability hands back configured ``openai`` clients, so the only DTOs it
5
+ owns are for control-plane discovery.
6
+
7
+ Discovery models mirror the control plane's ``AgentGatewayStatusResponse``
8
+ (agent_gateway_dto.rs:24-47) returned by ``GET /api/agentgateways?o={org}``,
9
+ carrying the per-environment (production/test) URLs. Live-verified 2026-07-07
10
+ against the control plane: the endpoint wraps items in the standard Page shape,
11
+ and slots carry extra fields (``id``, ``vendor``, ``runtime``,
12
+ ``manages_lifecycle``, ...) tolerated via ``extra="allow"``.
13
+ """
14
+
15
+ from pydantic import BaseModel, ConfigDict
16
+
17
+
18
+ class AgentGatewayEnvironmentResponse(BaseModel):
19
+ """One deployment slot (production or test) with its Cloud Run URL."""
20
+
21
+ model_config = ConfigDict(extra="allow")
22
+
23
+ environment: str
24
+ status: str
25
+ url: str | None = None
26
+ version: int | None = None
27
+
28
+
29
+ class AgentGatewayStatusResponse(BaseModel):
30
+ """Per-org gateway status: enabled flag plus the two environment slots."""
31
+
32
+ model_config = ConfigDict(extra="allow")
33
+
34
+ enabled: bool
35
+ code: str | None = None
36
+ production: AgentGatewayEnvironmentResponse | None = None
37
+ test: AgentGatewayEnvironmentResponse | None = None
@@ -0,0 +1,203 @@
1
+ """Client for the ontologies API (``/api/ontologies``).
2
+
3
+ :meth:`AgencyOntologyClient.list` is ``GET /api/ontologies`` (paged, optional
4
+ ``kind`` filter) so a caller can resolve a name → id. Export is
5
+ ``GET /api/ontologies/{id}/export``. Text formats (JSON, Turtle/OWL, SHACL,
6
+ package) return ``str``. ``package-zip`` is binary: :meth:`export` refuses it
7
+ and :meth:`export_bytes` returns ``bytes``. Agents that need classes, relations,
8
+ and properties to drive how they treat data should call :meth:`export_snapshot`.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import builtins # the `list()` method shadows the builtin, so annotations use builtins.list[...]
14
+ from typing import Any
15
+
16
+ from agency_sdk.delegates.base_client import BaseDelegateClient
17
+ from agency_sdk.delegates.ontology_dto import (
18
+ EntityDatasourceMappingDetail,
19
+ MappingsPagedResult,
20
+ OntologiesPagedResult,
21
+ OntologySnapshot,
22
+ QueryFilter,
23
+ QueryRequest,
24
+ QueryResult,
25
+ is_binary_export_format,
26
+ )
27
+
28
+
29
+ class AgencyOntologyClient(BaseDelegateClient):
30
+ api_path = "/api/ontologies"
31
+
32
+ def list(
33
+ self,
34
+ organisation_id: int,
35
+ *,
36
+ kind: str | None = None,
37
+ page: int = 0,
38
+ size: int = 10,
39
+ ) -> OntologiesPagedResult:
40
+ """List ontologies in the organisation (paged), for resolving a name → id.
41
+
42
+ Args:
43
+ organisation_id: The organisation ID.
44
+ kind: Optional filter: ``domain`` (working) or ``upper`` (importable).
45
+ page: Zero-indexed page number. Defaults to 0.
46
+ size: Page size (server default 10).
47
+
48
+ Name→id matching is the caller's job; this returns the raw page.
49
+ """
50
+ params: dict[str, str] = {"o": str(organisation_id), "p": str(page), "s": str(size)}
51
+ if kind is not None:
52
+ params["kind"] = kind
53
+ return OntologiesPagedResult(**self._make_request("GET", "", params=params))
54
+
55
+ def _export_params(
56
+ self,
57
+ organisation_id: int,
58
+ export_format: str | None,
59
+ branch: str | None,
60
+ version: str | None,
61
+ ) -> dict[str, str]:
62
+ params: dict[str, str] = {"o": str(organisation_id)}
63
+ if export_format is not None:
64
+ params["format"] = export_format
65
+ if branch is not None:
66
+ params["branch"] = branch
67
+ if version is not None:
68
+ params["version"] = version
69
+ return params
70
+
71
+ def _export_response(
72
+ self,
73
+ ontology_id: str,
74
+ organisation_id: int,
75
+ export_format: str | None,
76
+ branch: str | None,
77
+ version: str | None,
78
+ ) -> Any:
79
+ params = self._export_params(organisation_id, export_format, branch, version)
80
+ return self._request("GET", f"/{ontology_id}/export", params=params, json_content_type=False)
81
+
82
+ def export(
83
+ self,
84
+ ontology_id: str,
85
+ organisation_id: int,
86
+ export_format: str | None = None,
87
+ branch: str | None = None,
88
+ version: str | None = None,
89
+ ) -> str:
90
+ """Export an ontology as text.
91
+
92
+ Args:
93
+ ontology_id: The ontology ID.
94
+ organisation_id: The organisation ID.
95
+ export_format: ``json`` (default), ``owl``/``turtle``, ``shacl``,
96
+ ``shacl-package``, or ``package``. Zip aliases are refused — use
97
+ :meth:`export_bytes`. Unsupported values are a server ``400``.
98
+ branch: Branch whose latest snapshot is exported (server default ``main``).
99
+ version: Published version tag. When set, ``branch`` is not used.
100
+
101
+ Returns:
102
+ Response body decoded as text.
103
+
104
+ Raises:
105
+ ValueError: If ``export_format`` is a zip-package alias (binary).
106
+ """
107
+ if is_binary_export_format(export_format):
108
+ raise ValueError(f"format {export_format!r} is binary; use export_bytes() for package-zip")
109
+ response = self._export_response(ontology_id, organisation_id, export_format, branch, version)
110
+ text: str = response.text
111
+ return text
112
+
113
+ def export_bytes(
114
+ self,
115
+ ontology_id: str,
116
+ organisation_id: int,
117
+ export_format: str | None = None,
118
+ branch: str | None = None,
119
+ version: str | None = None,
120
+ ) -> bytes:
121
+ """Export an ontology as raw bytes (required for ``package-zip``).
122
+
123
+ Accepts every format :meth:`export` does, plus ``package-zip`` /
124
+ ``package-separate`` / ``zip``. Write the body to a file as bytes, not text.
125
+ """
126
+ response = self._export_response(ontology_id, organisation_id, export_format, branch, version)
127
+ content: bytes = response.content
128
+ return content
129
+
130
+ def export_snapshot(
131
+ self,
132
+ ontology_id: str,
133
+ organisation_id: int,
134
+ branch: str | None = None,
135
+ version: str | None = None,
136
+ ) -> OntologySnapshot:
137
+ """Export the JSON snapshot as a typed model for agent consumption.
138
+
139
+ Forces ``format=json``. Use this when an agent needs classes, relations,
140
+ and properties to drive how it treats data.
141
+ """
142
+ response = self._export_response(ontology_id, organisation_id, "json", branch, version)
143
+ body: dict[str, Any] = response.json()
144
+ return OntologySnapshot(**body)
145
+
146
+ def list_mappings(
147
+ self,
148
+ ontology_id: str,
149
+ organisation_id: int,
150
+ entity_id: str | None = None,
151
+ page: int = 0,
152
+ size: int = 10,
153
+ ) -> MappingsPagedResult:
154
+ """List entity-datasource mappings for an ontology."""
155
+ params: dict[str, str] = {"o": str(organisation_id), "s": str(size), "p": str(page)}
156
+ if entity_id is not None:
157
+ params["entity_id"] = entity_id
158
+ return MappingsPagedResult(**self._make_request("GET", f"/{ontology_id}/mappings", params=params))
159
+
160
+ def get_mapping(
161
+ self,
162
+ ontology_id: str,
163
+ mapping_id: str,
164
+ organisation_id: int,
165
+ ) -> EntityDatasourceMappingDetail:
166
+ """Get a specific entity-datasource mapping."""
167
+ params = {"o": str(organisation_id)}
168
+ return EntityDatasourceMappingDetail(
169
+ **self._make_request("GET", f"/{ontology_id}/mappings/{mapping_id}", params=params)
170
+ )
171
+
172
+ def query_entity(
173
+ self,
174
+ ontology_id: str,
175
+ entity_id: str,
176
+ organisation_id: int,
177
+ filters: builtins.list[QueryFilter] | None = None,
178
+ page: int = 0,
179
+ size: int = 25,
180
+ ) -> QueryResult:
181
+ """Query entity data through its active entity-datasource mapping.
182
+
183
+ Args:
184
+ ontology_id: The ontology identifier.
185
+ entity_id: The entity identifier within the ontology.
186
+ organisation_id: The organisation identifier.
187
+ filters: Filter conditions combined with AND. Defaults to no filters.
188
+ page: Zero-indexed page number. Defaults to 0.
189
+ size: Results per page (max 100). Defaults to 25.
190
+
191
+ Returns:
192
+ Query results with items, pagination info, and resolved mapping metadata.
193
+ """
194
+ params = {"o": str(organisation_id)}
195
+ body = QueryRequest(filters=filters or [], page=page, size=size)
196
+ return QueryResult(
197
+ **self._make_request(
198
+ "POST",
199
+ f"/{ontology_id}/entities/{entity_id}/data/_query",
200
+ data=body.model_dump(mode="json"),
201
+ params=params,
202
+ )
203
+ )
@@ -0,0 +1,221 @@
1
+ from enum import StrEnum
2
+ from typing import Any
3
+
4
+ from pydantic import BaseModel, ConfigDict, Field
5
+
6
+ from agency_sdk.delegates.datasets_dto import Page
7
+
8
+ #: Query-param aliases the Control Plane treats as `application/zip` (binary).
9
+ #: `export()` refuses these; use :meth:`AgencyOntologyClient.export_bytes`.
10
+ BINARY_EXPORT_FORMATS = frozenset({"package-zip", "package-separate", "zip"})
11
+
12
+
13
+ def is_binary_export_format(export_format: str | None) -> bool:
14
+ """True when ``export_format`` is a zip-package alias (case-insensitive)."""
15
+ return export_format is not None and export_format.lower() in BINARY_EXPORT_FORMATS
16
+
17
+
18
+ class OntologyStatus(StrEnum):
19
+ """Lifecycle status of an ontology (lowercase on the wire)."""
20
+
21
+ DRAFT = "draft"
22
+ PUBLISHED = "published"
23
+ DEPRECATED = "deprecated"
24
+ ARCHIVED = "archived"
25
+
26
+
27
+ class Ontology(BaseModel):
28
+ """List-view ontology from ``GET /api/ontologies``.
29
+
30
+ Wire format is snake_case (serde defaults). ``kind`` defaults to ``domain``
31
+ when omitted, matching the Control Plane. ``organization_id`` is the server
32
+ spelling.
33
+ """
34
+
35
+ model_config = ConfigDict(extra="allow")
36
+
37
+ id: str
38
+ name: str
39
+ display_name: str | None = None
40
+ description: str | None = None
41
+ status: OntologyStatus
42
+ kind: str = "domain"
43
+ created_at: str
44
+ updated_at: str
45
+ organization_id: int
46
+
47
+
48
+ class OntologiesPagedResult(BaseModel):
49
+ """Page-wrapped ``GET /api/ontologies`` response."""
50
+
51
+ page: Page
52
+ items: list[Ontology]
53
+
54
+
55
+ def _to_camel(name: str) -> str:
56
+ parts = name.split("_")
57
+ return parts[0] + "".join(p.capitalize() for p in parts[1:])
58
+
59
+
60
+ class EntityDatasourceMapping(BaseModel):
61
+ model_config = ConfigDict(alias_generator=_to_camel, populate_by_name=True)
62
+
63
+ id: str
64
+ ontology_id: str
65
+ datasource_id: str
66
+ datasource_name: str | None = None
67
+ entity_id: str
68
+ entity_label: str | None = None
69
+ mapping_type: str
70
+ description: str | None = None
71
+ status: str
72
+ target_name: str | None = None
73
+ created_at: str
74
+ updated_at: str
75
+
76
+
77
+ class RdbmsColumnMapping(BaseModel):
78
+ model_config = ConfigDict(alias_generator=_to_camel, populate_by_name=True)
79
+
80
+ id: str | None = None
81
+ property_name: str
82
+ column_id: str | None = None
83
+ column_name: str
84
+ alias: str | None = None
85
+ transformation: str | None = None
86
+ ordinal_position: int | None = None
87
+
88
+
89
+ class RdbmsMappingExtension(BaseModel):
90
+ model_config = ConfigDict(alias_generator=_to_camel, populate_by_name=True)
91
+
92
+ table_id: str | None = None
93
+ table_name: str
94
+ table_schema: str | None = None
95
+
96
+
97
+ class EntityDatasourceMappingDetail(BaseModel):
98
+ model_config = ConfigDict(alias_generator=_to_camel, populate_by_name=True)
99
+
100
+ id: str
101
+ ontology_id: str
102
+ datasource_id: str
103
+ datasource_name: str | None = None
104
+ entity_id: str
105
+ entity_label: str | None = None
106
+ mapping_type: str
107
+ description: str | None = None
108
+ status: str
109
+ target_name: str | None = None
110
+ generated_query: str | None = None
111
+ rdbms: RdbmsMappingExtension | None = None
112
+ column_mappings: list[RdbmsColumnMapping] | None = None
113
+ created_at: str
114
+ updated_at: str
115
+ created_by: str | None = None
116
+ updated_by: str | None = None
117
+
118
+
119
+ class MappingsPagedResult(BaseModel):
120
+ page: Page
121
+ items: list[EntityDatasourceMapping]
122
+
123
+
124
+ class QueryFilter(BaseModel):
125
+ """A filter condition for an entity data query."""
126
+
127
+ property: str
128
+ operator: str
129
+ value: Any | None = None
130
+
131
+
132
+ class QueryRequest(BaseModel):
133
+ """Request body for the entity data _query endpoint."""
134
+
135
+ filters: list[QueryFilter] = []
136
+ page: int = 0
137
+ size: int = 25
138
+
139
+
140
+ class QueryMappingInfo(BaseModel):
141
+ """Resolved mapping metadata returned with query results."""
142
+
143
+ model_config = ConfigDict(alias_generator=_to_camel, populate_by_name=True)
144
+
145
+ id: str
146
+ datasource_id: str
147
+ datasource_name: str
148
+ entity_label: str | None = None
149
+ status: str
150
+ generated_query: str | None = None
151
+
152
+
153
+ class QueryResult(BaseModel):
154
+ """Response from the entity data _query endpoint."""
155
+
156
+ items: list[dict[str, Any]]
157
+ page: Page
158
+ mapping: QueryMappingInfo
159
+
160
+
161
+ class PropertySnapshot(BaseModel):
162
+ """A reusable ``owl:ObjectProperty`` declaration from a JSON export.
163
+
164
+ Wire format is snake_case (serde defaults on the Control Plane snapshot).
165
+ ``extra="allow"`` so additive server fields do not break agents.
166
+ """
167
+
168
+ model_config = ConfigDict(extra="allow")
169
+
170
+ id: str
171
+ uri: str
172
+ label: str
173
+ description: str | None = None
174
+ sub_property_of: str | None = None
175
+ properties: dict[str, Any] = Field(default_factory=dict)
176
+
177
+
178
+ class EntitySnapshot(BaseModel):
179
+ """One entity in a JSON ontology export (class, individual, or property)."""
180
+
181
+ model_config = ConfigDict(extra="allow")
182
+
183
+ id: str
184
+ uri: str
185
+ label: str
186
+ description: str | None = None
187
+ entity_type: str
188
+ properties: dict[str, Any] = Field(default_factory=dict)
189
+ aliases: list[str] = Field(default_factory=list)
190
+
191
+
192
+ class RelationSnapshot(BaseModel):
193
+ """One relation in a JSON ontology export (``SubClassOf`` or ``ObjectProperty``)."""
194
+
195
+ model_config = ConfigDict(extra="allow")
196
+
197
+ id: str
198
+ uri: str
199
+ label: str
200
+ description: str | None = None
201
+ source_id: str
202
+ target_id: str
203
+ relation_type: str
204
+ property_id: str | None = None
205
+ min_count: int | None = None
206
+ max_count: int | None = None
207
+ properties: dict[str, Any] = Field(default_factory=dict)
208
+
209
+
210
+ class OntologySnapshot(BaseModel):
211
+ """JSON body of ``GET /api/ontologies/{id}/export?format=json``.
212
+
213
+ The agent-facing shape: iterate ``entities`` / ``relations`` / ``properties``
214
+ to decide how to treat data. Maps default to empty when a key is omitted.
215
+ """
216
+
217
+ model_config = ConfigDict(extra="allow")
218
+
219
+ entities: dict[str, EntitySnapshot] = Field(default_factory=dict)
220
+ relations: dict[str, RelationSnapshot] = Field(default_factory=dict)
221
+ properties: dict[str, PropertySnapshot] = Field(default_factory=dict)
@@ -0,0 +1,56 @@
1
+ from typing import Any
2
+
3
+ from agency_sdk.delegates.base_client import BaseDelegateClient
4
+ from agency_sdk.domain import (
5
+ CreatePromptCommand,
6
+ DeletePromptCommand,
7
+ PromptCommand,
8
+ PromptPagedResult,
9
+ PromptResponse,
10
+ PromptsCommand,
11
+ PublishPromptCommand,
12
+ SearchRequest,
13
+ UpdatePromptCommand,
14
+ )
15
+
16
+
17
+ class AgencyPromptsClient(BaseDelegateClient):
18
+ api_path = "/api/prompts"
19
+
20
+ def command(self, command: PromptsCommand) -> dict[str, Any]:
21
+ """Execute a command on the prompts API."""
22
+ return self._make_request("POST", "/_command", data=command.model_dump(mode="json"))
23
+
24
+ def create(self, command: CreatePromptCommand) -> dict[str, Any]:
25
+ """Create a new prompt."""
26
+ return self.command(command)
27
+
28
+ def search(self, request: SearchRequest) -> PromptPagedResult:
29
+ """Execute a search on the prompts API."""
30
+ return PromptPagedResult(**self._make_request("POST", "/_search", data=request.model_dump(mode="json")))
31
+
32
+ def prompt_command(self, prompt_id: str, command: PromptCommand) -> dict[str, Any]:
33
+ """Execute a command on a specific prompt."""
34
+ return self._make_request("POST", f"/{prompt_id}/_command", data=command.model_dump(mode="json"))
35
+
36
+ def update(self, prompt_id: str, command: UpdatePromptCommand) -> dict[str, Any]:
37
+ """Update an existing prompt."""
38
+ return self.prompt_command(prompt_id, command)
39
+
40
+ def publish(self, prompt_id: str, command: PublishPromptCommand) -> dict[str, Any]:
41
+ """Publish a prompt."""
42
+ return self.prompt_command(prompt_id, command)
43
+
44
+ def delete(self, prompt_id: str, command: DeletePromptCommand) -> dict[str, Any]:
45
+ """Delete a prompt."""
46
+ return self.prompt_command(prompt_id, command)
47
+
48
+ def list(self, organisation_id: int, page: int = 0, size: int = 10) -> PromptPagedResult:
49
+ """List all prompts for an organisation."""
50
+ params = {"o": str(organisation_id), "s": str(size), "p": str(page)}
51
+ return PromptPagedResult(**self._make_request("GET", "", params=params))
52
+
53
+ def get(self, prompt_id: str, organisation_id: int, version: str = "unpublished") -> PromptResponse:
54
+ """Get a specific prompt by ID."""
55
+ params = {"o": str(organisation_id), "v": version}
56
+ return PromptResponse(**self._make_request("GET", f"/{prompt_id}", params=params))
@@ -0,0 +1,33 @@
1
+ from agency_sdk.delegates.base_client import BaseDelegateClient
2
+ from agency_sdk.delegates.rules_dto import (
3
+ ExecuteRequest,
4
+ ExecutionResult,
5
+ ExecutionsPagedResult,
6
+ RuleDetail,
7
+ RulesPagedResult,
8
+ )
9
+
10
+
11
+ class AgencyRulesClient(BaseDelegateClient):
12
+ api_path = "/api/rules"
13
+
14
+ def list(self, organisation_id: int, page: int = 0, size: int = 10) -> RulesPagedResult:
15
+ params = {"o": str(organisation_id), "s": str(size), "p": str(page)}
16
+ return RulesPagedResult(**self._make_request("GET", "", params=params))
17
+
18
+ def get(self, rule_id: str, organisation_id: int, version_id: str | None = None) -> RuleDetail:
19
+ params: dict[str, str] = {"o": str(organisation_id)}
20
+ if version_id is not None:
21
+ params["v"] = version_id
22
+ return RuleDetail(**self._make_request("GET", f"/{rule_id}", params=params))
23
+
24
+ def execute(self, rule_id: str, request: ExecuteRequest) -> ExecutionResult:
25
+ data = request.model_dump(mode="json", by_alias=True)
26
+ result = self._make_request("POST", f"/{rule_id}/_execute", data=data)
27
+ return ExecutionResult(**result)
28
+
29
+ def list_executions(
30
+ self, rule_id: str, organisation_id: int, page: int = 0, size: int = 10
31
+ ) -> ExecutionsPagedResult:
32
+ params = {"o": str(organisation_id), "s": str(size), "p": str(page)}
33
+ return ExecutionsPagedResult(**self._make_request("GET", f"/{rule_id}/executions", params=params))