agentic-platform-sdk 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.
Files changed (41) hide show
  1. agentic_platform_sdk/__init__.py +9 -0
  2. agentic_platform_sdk/_a2a.py +133 -0
  3. agentic_platform_sdk/_client.py +152 -0
  4. agentic_platform_sdk/_contract.py +72 -0
  5. agentic_platform_sdk/_generated/__init__.py +0 -0
  6. agentic_platform_sdk/_generated/_base.py +20 -0
  7. agentic_platform_sdk/_generated/models.py +698 -0
  8. agentic_platform_sdk/_paging.py +117 -0
  9. agentic_platform_sdk/_spec/call_areas.json +13 -0
  10. agentic_platform_sdk/_spec/chat-events.schema.json +371 -0
  11. agentic_platform_sdk/_spec/errors.json +2365 -0
  12. agentic_platform_sdk/_spec/operations.json +230 -0
  13. agentic_platform_sdk/_transport.py +630 -0
  14. agentic_platform_sdk/_util.py +133 -0
  15. agentic_platform_sdk/agents.py +793 -0
  16. agentic_platform_sdk/approvals.py +66 -0
  17. agentic_platform_sdk/auth.py +336 -0
  18. agentic_platform_sdk/chat.py +599 -0
  19. agentic_platform_sdk/datasets.py +69 -0
  20. agentic_platform_sdk/errors.py +204 -0
  21. agentic_platform_sdk/kb.py +288 -0
  22. agentic_platform_sdk/llm.py +40 -0
  23. agentic_platform_sdk/me.py +28 -0
  24. agentic_platform_sdk/models.py +91 -0
  25. agentic_platform_sdk/ontology.py +209 -0
  26. agentic_platform_sdk/py.typed +0 -0
  27. agentic_platform_sdk/testing/__init__.py +19 -0
  28. agentic_platform_sdk/testing/conformance.py +803 -0
  29. agentic_platform_sdk/testing/fake.py +902 -0
  30. agentic_platform_sdk/testing/standin.py +165 -0
  31. agentic_platform_sdk/toolchains.py +137 -0
  32. agentic_platform_sdk/tools/__init__.py +70 -0
  33. agentic_platform_sdk/tools/_jcs.py +218 -0
  34. agentic_platform_sdk/tools/asgi.py +228 -0
  35. agentic_platform_sdk/tools/mcp.py +751 -0
  36. agentic_platform_sdk/tools/verify.py +379 -0
  37. agentic_platform_sdk/vision.py +300 -0
  38. agentic_platform_sdk-0.1.0.dist-info/METADATA +226 -0
  39. agentic_platform_sdk-0.1.0.dist-info/RECORD +41 -0
  40. agentic_platform_sdk-0.1.0.dist-info/WHEEL +4 -0
  41. agentic_platform_sdk-0.1.0.dist-info/licenses/LICENSE +202 -0
@@ -0,0 +1,9 @@
1
+ """Python SDK for the Agentic Platform Open API (/open/v1)."""
2
+
3
+ __version__ = "0.1.0"
4
+
5
+ from ._client import AgenticClient, AsyncAgenticClient # noqa: E402 - after __version__ (transport reads it)
6
+ from ._paging import Page # noqa: E402
7
+ from .vision import ModelDownload # noqa: E402
8
+
9
+ __all__ = ["AgenticClient", "AsyncAgenticClient", "ModelDownload", "Page", "__version__"]
@@ -0,0 +1,133 @@
1
+ """The A2A value types and their decoding, shared by ``agents`` (the client) and ``chat`` (the typed
2
+ chat events). A leaf module: it imports nothing of the SDK, so both can build on it."""
3
+
4
+ from __future__ import annotations
5
+
6
+ from dataclasses import dataclass, field
7
+ from typing import Any
8
+
9
+ # A2A 1.0 states after which a task sends no more updates (the stream closes on them too).
10
+ TERMINAL_STATES = frozenset(
11
+ {
12
+ "TASK_STATE_COMPLETED",
13
+ "TASK_STATE_FAILED",
14
+ "TASK_STATE_CANCELED",
15
+ "TASK_STATE_REJECTED",
16
+ }
17
+ )
18
+ _INTERRUPTED_STATES = frozenset({"TASK_STATE_INPUT_REQUIRED", "TASK_STATE_AUTH_REQUIRED"})
19
+
20
+
21
+ # --- types -----------------------------------------------------------------------------------
22
+
23
+
24
+ @dataclass(frozen=True)
25
+ class Task:
26
+ """An A2A task. ``state`` is the wire value (``TASK_STATE_COMPLETED``, ...). ``text`` joins
27
+ the text parts of every artifact; ``artifacts`` and ``raw`` hold the rest as sent."""
28
+
29
+ id: str
30
+ context_id: str
31
+ state: str
32
+ text: str = ""
33
+ artifacts: list[dict[str, Any]] = field(default_factory=list)
34
+ raw: dict[str, Any] = field(default_factory=dict)
35
+
36
+
37
+ @dataclass(frozen=True)
38
+ class StatusUpdate:
39
+ task_id: str
40
+ context_id: str
41
+ state: str
42
+ final: bool
43
+
44
+
45
+ @dataclass(frozen=True)
46
+ class ArtifactUpdate:
47
+ task_id: str
48
+ artifact_id: str
49
+ text: str
50
+ append: bool
51
+ last_chunk: bool
52
+
53
+
54
+ @dataclass(frozen=True)
55
+ class TaskSnapshot:
56
+ task: Task
57
+
58
+
59
+ @dataclass(frozen=True)
60
+ class Unknown:
61
+ """An event the SDK does not know: its ``kind`` (the result's first key, or ``"malformed"``;
62
+ for a chat event, its ``type``) and the decoded payload. `seq` is the chat-events sequence
63
+ number of the frame, when it carried one (a chat stream counts it even for an unknown type)."""
64
+
65
+ kind: str
66
+ raw: dict[str, Any]
67
+ seq: int | None = None
68
+
69
+
70
+ Event = TaskSnapshot | StatusUpdate | ArtifactUpdate | Unknown
71
+
72
+
73
+ # --- decoding --------------------------------------------------------------------------------
74
+
75
+
76
+ def _text_of(parts: Any) -> str:
77
+ if not isinstance(parts, list):
78
+ return ""
79
+ return "".join(
80
+ part["text"]
81
+ for part in parts
82
+ if isinstance(part, dict) and isinstance(part.get("text"), str)
83
+ )
84
+
85
+
86
+ def _str(value: Any) -> str:
87
+ return value if isinstance(value, str) else ""
88
+
89
+
90
+ def _task(raw: dict[str, Any]) -> Task:
91
+ status = raw.get("status")
92
+ artifacts = [a for a in raw.get("artifacts") or [] if isinstance(a, dict)]
93
+ return Task(
94
+ id=_str(raw.get("id")),
95
+ context_id=_str(raw.get("contextId")),
96
+ state=_str(status.get("state")) if isinstance(status, dict) else "",
97
+ text="".join(_text_of(a.get("parts")) for a in artifacts),
98
+ artifacts=artifacts,
99
+ raw=raw,
100
+ )
101
+
102
+
103
+ def _status_update(raw: dict[str, Any]) -> StatusUpdate:
104
+ status = raw.get("status")
105
+ state = _str(status.get("state")) if isinstance(status, dict) else ""
106
+ final = raw.get("final")
107
+ if not isinstance(final, bool):
108
+ final = state in TERMINAL_STATES or state in _INTERRUPTED_STATES
109
+ return StatusUpdate(_str(raw.get("taskId")), _str(raw.get("contextId")), state, final)
110
+
111
+
112
+ def _artifact_update(raw: dict[str, Any]) -> ArtifactUpdate:
113
+ artifact = raw.get("artifact")
114
+ artifact = artifact if isinstance(artifact, dict) else {}
115
+ return ArtifactUpdate(
116
+ task_id=_str(raw.get("taskId")),
117
+ artifact_id=_str(artifact.get("artifactId")),
118
+ text=_text_of(artifact.get("parts")),
119
+ append=raw.get("append") is True,
120
+ last_chunk=raw.get("lastChunk") is True,
121
+ )
122
+
123
+
124
+ def _event_of(result: dict[str, Any]) -> Event:
125
+ for kind, build in (
126
+ ("task", lambda raw: TaskSnapshot(_task(raw))),
127
+ ("statusUpdate", _status_update),
128
+ ("artifactUpdate", _artifact_update),
129
+ ):
130
+ raw = result.get(kind)
131
+ if isinstance(raw, dict):
132
+ return build(raw)
133
+ return Unknown(next(iter(result), ""), result)
@@ -0,0 +1,152 @@
1
+ """The public clients: ``AgenticClient`` (blocking) and ``AsyncAgenticClient``.
2
+
3
+ A client builds one transport from its constructor arguments and hands it to each area.
4
+ ``for_workspace`` returns a client with the same configuration for another workspace.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import Any
10
+
11
+ from ._transport import AsyncTransport, Call, RetryConfig, SyncTransport
12
+ from .agents import Agents, AsyncAgents
13
+ from .approvals import ApprovalsArea, AsyncApprovalsArea
14
+ from .auth import DPoPKey, TokenProvider
15
+ from .datasets import AsyncDatasetsArea, DatasetsArea
16
+ from .kb import AsyncKbArea, KbArea
17
+ from .llm import AsyncLlmArea, LlmArea
18
+ from .me import AsyncMeArea, MeArea
19
+ from .models import AsyncModelsArea, ModelsArea
20
+ from .ontology import AsyncOntologyArea, OntologyArea
21
+ from .toolchains import AsyncToolchainsArea, ToolchainsArea
22
+ from .vision import AsyncVisionArea, VisionArea
23
+
24
+ _CONTRACT = Call(operation="getOpenApiDocument", area="meta")
25
+
26
+
27
+ def _version_of(document: Any) -> str:
28
+ return str(document["info"]["version"])
29
+
30
+
31
+ class AgenticClient:
32
+ """The blocking client. ``pooled=False`` (the default) opens a connection per call; set
33
+ ``pooled=True`` to reuse one and ``close()`` (or use ``with``) to release it."""
34
+
35
+ def __init__(
36
+ self,
37
+ base_url: str,
38
+ token: TokenProvider,
39
+ workspace_id: str | None = None,
40
+ *,
41
+ dpop: DPoPKey | None = None,
42
+ retry: RetryConfig | None = None,
43
+ timeouts: dict[str, float] | None = None,
44
+ pooled: bool = False,
45
+ ) -> None:
46
+ self._settings: dict[str, Any] = {
47
+ "base_url": base_url,
48
+ "token": token,
49
+ "dpop": dpop,
50
+ "retry": retry,
51
+ "timeouts": timeouts,
52
+ "pooled": pooled,
53
+ }
54
+ self.workspace_id = workspace_id
55
+ self._transport = SyncTransport(
56
+ base_url,
57
+ token,
58
+ workspace_id,
59
+ dpop=dpop,
60
+ retry=retry or RetryConfig(),
61
+ timeouts=timeouts,
62
+ pooled=pooled,
63
+ )
64
+ self.me = MeArea(self._transport)
65
+ self.models = ModelsArea(self._transport)
66
+ self.llm = LlmArea(self._transport)
67
+ self.kb = KbArea(self._transport)
68
+ self.datasets = DatasetsArea(self._transport)
69
+ self.ontology = OntologyArea(self._transport)
70
+ self.vision = VisionArea(self._transport)
71
+ self.toolchains = ToolchainsArea(self._transport)
72
+ self.agents = Agents(self._transport)
73
+ self.approvals = ApprovalsArea(self._transport)
74
+
75
+ def for_workspace(self, workspace_id: str) -> AgenticClient:
76
+ """A client for `workspace_id` with this client's token, DPoP key, retry and timeouts."""
77
+ return AgenticClient(workspace_id=workspace_id, **self._settings)
78
+
79
+ def contract_version(self) -> str:
80
+ """The platform's contract version: ``info.version`` of ``/open/v1/openapi.json``."""
81
+ return _version_of(self._transport.request(_CONTRACT).json())
82
+
83
+ def close(self) -> None:
84
+ self._transport.close()
85
+
86
+ def __enter__(self) -> AgenticClient:
87
+ return self
88
+
89
+ def __exit__(self, *exc_info: object) -> None:
90
+ self.close()
91
+
92
+
93
+ class AsyncAgenticClient:
94
+ """The async client: the same names as ``AgenticClient``, awaited."""
95
+
96
+ def __init__(
97
+ self,
98
+ base_url: str,
99
+ token: TokenProvider,
100
+ workspace_id: str | None = None,
101
+ *,
102
+ dpop: DPoPKey | None = None,
103
+ retry: RetryConfig | None = None,
104
+ timeouts: dict[str, float] | None = None,
105
+ pooled: bool = False,
106
+ ) -> None:
107
+ self._settings: dict[str, Any] = {
108
+ "base_url": base_url,
109
+ "token": token,
110
+ "dpop": dpop,
111
+ "retry": retry,
112
+ "timeouts": timeouts,
113
+ "pooled": pooled,
114
+ }
115
+ self.workspace_id = workspace_id
116
+ self._transport = AsyncTransport(
117
+ base_url,
118
+ token,
119
+ workspace_id,
120
+ dpop=dpop,
121
+ retry=retry or RetryConfig(),
122
+ timeouts=timeouts,
123
+ pooled=pooled,
124
+ )
125
+ self.me = AsyncMeArea(self._transport)
126
+ self.models = AsyncModelsArea(self._transport)
127
+ self.llm = AsyncLlmArea(self._transport)
128
+ self.kb = AsyncKbArea(self._transport)
129
+ self.datasets = AsyncDatasetsArea(self._transport)
130
+ self.ontology = AsyncOntologyArea(self._transport)
131
+ self.vision = AsyncVisionArea(self._transport)
132
+ self.toolchains = AsyncToolchainsArea(self._transport)
133
+ self.agents = AsyncAgents(self._transport)
134
+ self.approvals = AsyncApprovalsArea(self._transport)
135
+
136
+ def for_workspace(self, workspace_id: str) -> AsyncAgenticClient:
137
+ return AsyncAgenticClient(workspace_id=workspace_id, **self._settings)
138
+
139
+ async def contract_version(self) -> str:
140
+ return _version_of((await self._transport.request(_CONTRACT)).json())
141
+
142
+ async def aclose(self) -> None:
143
+ await self._transport.aclose()
144
+
145
+ async def __aenter__(self) -> AsyncAgenticClient:
146
+ return self
147
+
148
+ async def __aexit__(self, *exc_info: object) -> None:
149
+ await self.aclose()
150
+
151
+
152
+ __all__ = ["AgenticClient", "AsyncAgenticClient"]
@@ -0,0 +1,72 @@
1
+ """The API contract as data: operations, error catalogue and call areas.
2
+
3
+ Everything here is read from the packaged copies in ``_spec/`` that ``scripts/generate.py`` writes
4
+ from the contract files of the platform's source repository, so an installed package never reads
5
+ them at runtime.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ from dataclasses import dataclass
12
+ from pathlib import Path
13
+
14
+ _SPEC = Path(__file__).resolve().parent / "_spec"
15
+
16
+
17
+ @dataclass(frozen=True)
18
+ class Operation:
19
+ method: str
20
+ path: str
21
+ safe_retry: bool
22
+ idempotency_key: bool
23
+
24
+
25
+ @dataclass(frozen=True)
26
+ class ErrorInfo:
27
+ http_status: tuple[int, ...]
28
+ retryable: bool
29
+ refused_before_run: bool
30
+ carried_in: str # "status" (the default), "body" or "both"
31
+
32
+
33
+ def _load(name: str) -> dict:
34
+ return json.loads((_SPEC / name).read_text(encoding="utf-8"))
35
+
36
+
37
+ OPERATIONS: dict[str, Operation] = {
38
+ operation_id: Operation(**fields) for operation_id, fields in _load("operations.json").items()
39
+ }
40
+
41
+ ERRORS: dict[str, ErrorInfo] = {
42
+ entry["code"]: ErrorInfo(
43
+ http_status=tuple(entry["http_status"]),
44
+ retryable=entry["retryable"],
45
+ refused_before_run=entry["refused_before_run"],
46
+ carried_in=entry.get("carried_in", "status"),
47
+ )
48
+ for entry in _load("errors.json")["codes"]
49
+ }
50
+
51
+ # SDK client area -> catalogue area (the contract's call-area table).
52
+ CATALOGUE_AREA: dict[str, str] = _load("call_areas.json")
53
+
54
+ _AREAS = frozenset(CATALOGUE_AREA.values())
55
+
56
+
57
+ def is_retryable(code: str) -> bool:
58
+ """Whether the catalogue marks `code` retryable.
59
+
60
+ A code outside the catalogue matches a ``*.<name>`` pattern entry only when its prefix is a
61
+ catalogue area, so ``knowledge_base.unavailable`` is retryable and ``kb_typo.unavailable`` is
62
+ not. Whether the request is also safe to repeat is the caller's decision.
63
+ """
64
+ info = ERRORS.get(code)
65
+ if info is not None:
66
+ return info.retryable
67
+ area, dot, name = code.partition(".")
68
+ if dot and area in _AREAS:
69
+ pattern = ERRORS.get(f"*.{name}")
70
+ if pattern is not None:
71
+ return pattern.retryable
72
+ return False
File without changes
@@ -0,0 +1,20 @@
1
+ """Base of every generated model. Generated by scripts/generate.py; do not edit."""
2
+
3
+ from datetime import UTC, datetime
4
+ from typing import Annotated
5
+
6
+ from pydantic import AfterValidator, BaseModel, ConfigDict
7
+
8
+
9
+ def _naive_is_utc(value: datetime) -> datetime:
10
+ return value.replace(tzinfo=UTC) if value.tzinfo is None else value
11
+
12
+
13
+ # The platform answers with naive ISO datetimes ("2026-10-16T08:32:00.332613", no offset): UTC.
14
+ # Every generated date-time field is this type: a naive value becomes UTC-aware, an aware one is
15
+ # kept exactly (offset included), anything that is not a datetime still fails validation.
16
+ UtcDatetime = Annotated[datetime, AfterValidator(_naive_is_utc)]
17
+
18
+
19
+ class Base(BaseModel):
20
+ model_config = ConfigDict(extra="allow", populate_by_name=True)