MACAWClient
The core SDK for the MACAW Trust Layer. Provides cryptographic identity, policy enforcement, and audit logging for AI agents and applications.
Installation
Install with macaw-ai, which also connects a workspace. Or download it from the MACAW console (Dev Hub → Download MACAW Client SDK); the download includes your workspace API key. Python 3.12 or 3.14 (Windows: 3.14).
# Install the client SDK and adapters
npm install -g macaw-ai && macaw-ai install --client
# Or, from the console download (Dev Hub → Download MACAW Client SDK):
pip install macaw_client-*.whl "./secureAI[all]"Quick Start
Create a client, register with the Control Plane, invoke a tool, then clean up.
from macaw_client import MACAWClient
client = MACAWClient(app_name="my-agent")
client.register()
result = client.invoke_tool("database", {
"query": "SELECT * FROM sales"
})
client.unregister()Constructor
Create a client instance. Not connected until register() is called.
MACAWClient(
app_name: str, # Required
app_version: str = "1.0.0",
agent_type: str = "agent", # "agent" | "user" | "service"
user_name: str = None,
iam_token: str = None, # Required if agent_type="user"
provider: str = None,
service_account: str = None,
intent_policy: dict = None,
tools: dict = None
)| Parameter | Type | Description |
|---|---|---|
app_namerequired | str | Unique application identifier. |
app_version | str | Version string. Default: "1.0.0" |
agent_type | str | "agent" (autonomous), "user" (human-backed), or "service". |
user_name | str | Human identifier. Example: "alice@sales-bot" |
iam_token | str | JWT from enterprise IDP. |
provider | str | IDP hint. Example: "okta", "keycloak" |
service_account | str | Service account name. |
intent_policy | dict | MAPL policy for permitted operations. |
tools | dict | Tools this agent provides. |
agent_type="user", iam_token is required and service_account must not be set.Methods
Registration with Control Plane
register()→boolCreates cryptographic identity and joins the mesh. Embedded tools are registered with the Agent Registry.
unregister()→NoneClean up and leave the mesh.
Tool Operations
invoke_tool(tool_name, parameters, target_agent=None, stream=False, intent_policy=None)→dict | IteratorExecutes a signed, policy-enforced tool call. Optional intent_policy overrides the agent's default intent policy for this invocation.
register_tool(name, handler, prompts=None, attestation_config=None)→NoneRegisters a tool handler. Use prompts for content filtering.
Agent Discovery
list_agents(agent_type=None)→List[dict]Lists registered agents. Filter by "user", "service", "tool", "app".
get_agent_info(agent_id)→dict | NoneReturns agent details: tools, metadata, intent_policy.
External Attestations
list_attestations(status=None)→List[dict]List attestations visible to this agent. Filter by status: "pending", "approved", "denied", "expired".
approve_attestation(attestation, reason=None)→boolApprove a pending external attestation. Caller must match approval_criteria. Cryptographically signed.
deny_attestation(attestation, reason=None)→boolDeny a pending external attestation. Caller must match approval_criteria. Requestor receives denial with reason.
App Context Vault
context_set(key: str, value: Any)→NoneStores value in context vault. Associated with authenticated principal. Audit-logged.
context_get(key: str)→AnyRetrieves value from context vault. Returns None if not found. Audit-logged.
Authenticated Prompts
create_authenticated_prompt(prompt_text, metadata=None)→AuthenticatedPromptCreates signed prompt. ROOT if none active, else DERIVED.
switch_prompt(prompt)→AuthenticatedPrompt | NoneSwitches context. Pass None, prompt_id, or AuthenticatedPrompt.
get_current_prompt()→AuthenticatedPrompt | NoneReturns the active prompt.
Custom Logging
log_event(event_type, source, action, target, outcome, signed=False)→boolWrites to audit log. Use signed=True for compliance events.
Examples
User Identity with Enterprise IDP
JWT claims (roles, groups) are used for policy resolution.
from macaw_client import MACAWClient
from macaw_client import RemoteIdentityProvider
idp = RemoteIdentityProvider()
token, principal = idp.login("alice@company.com", password)
client = MACAWClient(
app_name="sales-assistant",
agent_type="user",
iam_token=token
)
client.register()
result = client.invoke_tool("crm", {
"customer_id": "12345"
})Prompt Lineage
Derived prompts inherit and narrow the parent's scope.
client = MACAWClient(app_name="analyst")
client.register()
root = client.create_authenticated_prompt(
"Analyze Q4 financials",
metadata={"source": "cfo"}
)
# Auto-derives from root
refined = client.create_authenticated_prompt(
"Focus on APAC expenses"
)
# refined.parent_id == root.prompt_idMulti-Session Context
Manage separate prompt trees per user session.
# Session 1: Alice
alice = client.create_authenticated_prompt(
"Show budget",
metadata={"user": "alice"}
)
# Switch to Session 2: Bob
client.switch_prompt(None)
bob = client.create_authenticated_prompt(
"List tickets",
metadata={"user": "bob"}
)
# Return to Alice
client.switch_prompt(alice.prompt_id)