maigp-client 5.0.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 (45) hide show
  1. aigp_client/__init__.py +64 -0
  2. aigp_client/african_context.py +102 -0
  3. aigp_client/agent_client.py +619 -0
  4. aigp_client/anticipation.py +72 -0
  5. aigp_client/backoff.py +32 -0
  6. aigp_client/client.py +658 -0
  7. aigp_client/config.py +62 -0
  8. aigp_client/context.py +112 -0
  9. aigp_client/delegation.py +66 -0
  10. aigp_client/govern.py +25 -0
  11. aigp_client/japanese_context.py +83 -0
  12. aigp_client/logger.py +35 -0
  13. aigp_client/providers/__init__.py +10 -0
  14. aigp_client/providers/consent/__init__.py +6 -0
  15. aigp_client/providers/consent/consent_helper_base.py +31 -0
  16. aigp_client/providers/consent/default/__init__.py +0 -0
  17. aigp_client/providers/consent/default/passthrough_helper.py +13 -0
  18. aigp_client/providers/model/__init__.py +7 -0
  19. aigp_client/providers/model/azure_openai/__init__.py +0 -0
  20. aigp_client/providers/model/bedrock/__init__.py +0 -0
  21. aigp_client/providers/model/bedrock/bedrock_model_provider.py +75 -0
  22. aigp_client/providers/model/model_provider_base.py +38 -0
  23. aigp_client/providers/model/model_provider_factory.py +24 -0
  24. aigp_client/providers/model/vertex/__init__.py +0 -0
  25. aigp_client/providers/storage/__init__.py +5 -0
  26. aigp_client/providers/storage/local/__init__.py +5 -0
  27. aigp_client/providers/storage/local/local_storage_provider.py +54 -0
  28. aigp_client/providers/storage/s3/__init__.py +5 -0
  29. aigp_client/providers/storage/s3/s3_storage_provider.py +56 -0
  30. aigp_client/providers/storage/storage_provider_base.py +32 -0
  31. aigp_client/providers/transport/__init__.py +6 -0
  32. aigp_client/providers/transport/httpx/__init__.py +0 -0
  33. aigp_client/providers/transport/httpx/httpx_transport.py +29 -0
  34. aigp_client/providers/transport/transport_base.py +24 -0
  35. aigp_client/regulatory.py +81 -0
  36. aigp_client/schemas/__init__.py +5 -0
  37. aigp_client/schemas/geo.py +106 -0
  38. aigp_client/session.py +28 -0
  39. aigp_client/streaming.py +71 -0
  40. aigp_client/tokens.py +46 -0
  41. aigp_client/tools.py +50 -0
  42. aigp_client/trace_builder.py +140 -0
  43. maigp_client-5.0.0.dist-info/METADATA +178 -0
  44. maigp_client-5.0.0.dist-info/RECORD +45 -0
  45. maigp_client-5.0.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,64 @@
1
+ """AIGP Client v4.0 — Universal AI Governance Protocol client.
2
+
3
+ Provides:
4
+ - Protocol transport (CHECK/RECORD/TRACE)
5
+ - Session context for multi-agent linking
6
+ - Token accumulation for streaming/multi-cycle
7
+ - Tool governance (per-tool CHECK)
8
+ - Delegation tokens (agent-to-agent scoping)
9
+ - Stream accumulator (periodic RECORD during streaming)
10
+ - Rate-limit backoff
11
+ """
12
+
13
+ __version__ = "4.0.0"
14
+
15
+ # Core protocol
16
+ from .client import AigpClient, GovernanceDecision
17
+ from .trace_builder import TraceBuilder, STAGE_NAMES
18
+ from .context import HumanitarianContext
19
+ from .regulatory import RegulatoryContext
20
+ from .african_context import AfricanContext
21
+ from .japanese_context import JapaneseContext
22
+
23
+ # v3.0+ — Agent support
24
+ from .session import SessionContext
25
+ from .tokens import TokenAccumulator
26
+ from .tools import ToolGovernance
27
+ from .delegation import DelegationToken
28
+ from .streaming import StreamAccumulator
29
+ from .backoff import retry_on_rate_limit
30
+
31
+ # One-line governance wrapper
32
+ from .govern import govern
33
+
34
+ # RFC-032: Anticipation
35
+ from .anticipation import AnticipationBuilder, Criterion
36
+
37
+ # Provider-based config
38
+ from .config import ClientConfig, ClientComponents
39
+ from .providers.model import ModelProviderBase
40
+ from .providers.transport import TransportProviderBase
41
+ from .providers.consent import ConsentHelperBase, TokenMap
42
+ from .schemas import GeoContext
43
+
44
+ __all__ = [
45
+ # Core
46
+ "AigpClient", "GovernanceDecision",
47
+ "TraceBuilder", "STAGE_NAMES",
48
+ "HumanitarianContext",
49
+ "RegulatoryContext",
50
+ "AfricanContext",
51
+ "JapaneseContext",
52
+ # v3.0+ Agent support
53
+ "SessionContext", "TokenAccumulator", "ToolGovernance",
54
+ "DelegationToken", "StreamAccumulator", "retry_on_rate_limit",
55
+ # Config/Providers
56
+ "ClientConfig", "ClientComponents",
57
+ "ModelProviderBase", "TransportProviderBase",
58
+ "ConsentHelperBase", "TokenMap",
59
+ "GeoContext",
60
+ # Governance wrapper
61
+ "govern",
62
+ # RFC-032: Anticipation
63
+ "AnticipationBuilder", "Criterion",
64
+ ]
@@ -0,0 +1,102 @@
1
+ """RFC-029: African Context — typed context for AU Continental AI Strategy alignment.
2
+
3
+ Usage:
4
+ from aigp_client.african_context import AfricanContext
5
+
6
+ ctx = AfricanContext(
7
+ active=True,
8
+ governance_framework="AU_CONTINENTAL_AI_STRATEGY",
9
+ member_state="KE",
10
+ rec="EAC",
11
+ )
12
+ client.declare_african_context(ctx)
13
+ """
14
+
15
+ from dataclasses import dataclass, field
16
+
17
+ VALID_FRAMEWORKS = {"AU_CONTINENTAL_AI_STRATEGY"}
18
+ VALID_RECS = {"EAC", "ECOWAS", "SADC", "COMESA", "AMU", "IGAD", "ECCAS", "CEN-SAD"}
19
+ VALID_SECTORS = {"HEALTH", "AGRICULTURE", "EDUCATION", "PUBLIC_SERVICES", "FINANCE", "ENVIRONMENT"}
20
+ VALID_BENEFICIARIES = {"YOUTH", "WOMEN", "RURAL_COMMUNITIES", "DISABLED", "ELDERLY"}
21
+ VALID_CROSS_BORDER = {"MALABO_CONVENTION", "AU_DATA_POLICY_FRAMEWORK"}
22
+
23
+
24
+ @dataclass
25
+ class AfricanContext:
26
+ """AU Continental AI Strategy context declaration per RFC-029."""
27
+
28
+ active: bool
29
+ governance_framework: str
30
+ member_state: str
31
+ rec: str = ""
32
+ local_first: bool = False
33
+ ubuntu_principle: bool = False
34
+ priority_sector: str = ""
35
+ beneficiary_groups: list[str] = field(default_factory=list)
36
+ language_context: list[str] = field(default_factory=list)
37
+ data_sovereignty: dict = field(default_factory=dict)
38
+ cultural_sensitivity: dict = field(default_factory=dict)
39
+
40
+ def __post_init__(self):
41
+ self.validate()
42
+
43
+ def validate(self) -> None:
44
+ """Raise ValueError if context is invalid."""
45
+ if self.governance_framework not in VALID_FRAMEWORKS:
46
+ raise ValueError(f"Invalid governance_framework: {self.governance_framework}. Must be one of {VALID_FRAMEWORKS}")
47
+ if not self.member_state or len(self.member_state) != 2:
48
+ raise ValueError("member_state must be a 2-letter ISO 3166-1 alpha-2 code")
49
+ if self.rec and self.rec not in VALID_RECS:
50
+ raise ValueError(f"Invalid rec: {self.rec}. Must be one of {VALID_RECS}")
51
+ if self.priority_sector and self.priority_sector not in VALID_SECTORS:
52
+ raise ValueError(f"Invalid priority_sector: {self.priority_sector}. Must be one of {VALID_SECTORS}")
53
+ for bg in self.beneficiary_groups:
54
+ if bg not in VALID_BENEFICIARIES:
55
+ raise ValueError(f"Invalid beneficiary_group: {bg}. Must be one of {VALID_BENEFICIARIES}")
56
+ if self.data_sovereignty:
57
+ cbf = self.data_sovereignty.get("cross_border_framework")
58
+ if cbf and cbf not in VALID_CROSS_BORDER:
59
+ raise ValueError(f"Invalid cross_border_framework: {cbf}. Must be one of {VALID_CROSS_BORDER}")
60
+
61
+ def to_dict(self) -> dict:
62
+ """Serialize for protocol transmission."""
63
+ d = {
64
+ "active": self.active,
65
+ "governance_framework": self.governance_framework,
66
+ "member_state": self.member_state,
67
+ "local_first": self.local_first,
68
+ "ubuntu_principle": self.ubuntu_principle,
69
+ }
70
+ if self.rec:
71
+ d["rec"] = self.rec
72
+ if self.priority_sector:
73
+ d["priority_sector"] = self.priority_sector
74
+ if self.beneficiary_groups:
75
+ d["beneficiary_groups"] = self.beneficiary_groups
76
+ if self.language_context:
77
+ d["language_context"] = self.language_context
78
+ if self.data_sovereignty:
79
+ d["data_sovereignty"] = self.data_sovereignty
80
+ if self.cultural_sensitivity:
81
+ d["cultural_sensitivity"] = self.cultural_sensitivity
82
+ return d
83
+
84
+ def merge(self, request_level: dict) -> "AfricanContext":
85
+ """Merge request-level context. Escalation only — cannot downgrade."""
86
+ if not request_level:
87
+ return self
88
+ if request_level.get("active") is False:
89
+ request_level["active"] = True
90
+ return AfricanContext(
91
+ active=True,
92
+ governance_framework=request_level.get("governance_framework", self.governance_framework),
93
+ member_state=request_level.get("member_state", self.member_state),
94
+ rec=request_level.get("rec", self.rec),
95
+ local_first=request_level.get("local_first", self.local_first),
96
+ ubuntu_principle=request_level.get("ubuntu_principle", self.ubuntu_principle),
97
+ priority_sector=request_level.get("priority_sector", self.priority_sector),
98
+ beneficiary_groups=list(set(self.beneficiary_groups + request_level.get("beneficiary_groups", []))),
99
+ language_context=list(set(self.language_context + request_level.get("language_context", []))),
100
+ data_sovereignty=request_level.get("data_sovereignty", self.data_sovereignty),
101
+ cultural_sensitivity=request_level.get("cultural_sensitivity", self.cultural_sensitivity),
102
+ )