AgentRuntimePrincipal establishes a default-deny boundary for Harnest-governed capabilities during one invocation. A server tool, client-hosted tool, or MCP operation is available only when it declares a permission carried by the principal. Create the principal in trusted application code after authenticating the caller or deciding which service identity a job should use.
id is an opaque runtime identity. Your application remains the source of user, tenant, role, and policy decisions.
Mark permissioned capabilities
Every capability that should remain available under a principal must declare a permission. Server and client-hosted tools accept one permission identifier:mcp/catalog.py
permission= applies to every tool from that client. A matching tool_permissions entry is an additional requirement. Permission identifiers start with a letter and can contain letters, numbers, ., _, :, or -.
When you omit the client-wide permission, only operations named in tool_permissions can be available under a principal. Untagged MCP operations remain unavailable.
Invoke with a principal
Pass the principal through a trusted custom HTTP endpoint:agent_principal= to an in-process AgentSession.invoke(...) or AgentSession.stream(...) call.
Harnest removes untagged and unmatched capabilities from Harnest-owned model tool surfaces and checks the permission again at execution. Treat the execution check as defense in depth. The downstream service must still authorize the actual operation.
Understand omission and propagation
Queued Task and external-continuation states contain only permission identifiers. They do not serialize the principal ID, authentication claims, or credentials. A scheduled Task can construct and pass an explicit service principal in trusted task code when it needs declared capabilities.
Managed and advanced modes
In advanced mode, Harnest enforces the principal for Harnest-decorated server tools, client-hosted tools, configured MCP clients, local agent invocation, and queued Task propagation when those operations cross Harnest runtime boundaries.
Harnest does not rewrite a native graph, inspect every framework plugin, or wrap tools that you wire directly into your own agent graph. Those user-owned paths remain your responsibility and can bypass runtime-principal projection. Enforce equivalent policy in the native graph or downstream gateway when you need complete coverage.
The principal is private runtime state rather than a property on
harnest.context. Tools and extensions declare required permissions; they do not read or make policy decisions from the active principal.