Skip to main content

cred-autogen

Microsoft AutoGen integration for Cred. OAuth2 credential delegation for AI agents.

Install

pip install cred-autogen

Quick Start

import os
from cred_autogen import cred_delegate_tool, cred_use_tool
from cred import AgentIdentity

# The agent's own did:key identity, created once with cred.generate_agent_identity()
# and persisted with identity.export(); load_agent_identity() stands for your own
# secret store lookup returning that dict.
identity = AgentIdentity.from_export(load_agent_identity())

tool = cred_delegate_tool(
    agent_token=os.environ["CRED_AGENT_TOKEN"],
    base_url=os.environ["CRED_BASE_URL"],
    user_id="user_123",
    app_client_id="my_app_client_id",
    token_format="handle",
    agent_identity=identity,
)

# Register with an AutoGen AssistantAgent
from autogen_agentchat.agents import AssistantAgent

agent = AssistantAgent(
    name="assistant",
    tools=[tool, cred_use_tool(
        agent_token=os.environ["CRED_AGENT_TOKEN"],
        base_url=os.environ["CRED_BASE_URL"],
        agent_identity=identity,
    )],
)

Tool Schema

The cred_delegate tool accepts:

Parameter Type Description
service string Service slug (e.g. google, github)
scopes string[] OAuth scopes to request

user_id and app_client_id are pre-configured at factory time, not agent-controlled.

By default, cred_delegate_tool returns a legacy access token for backwards compatibility. Set token_format="handle" to return a brokered delegation id, then use cred_use_tool to make allowed service API calls without exposing provider access tokens.

agent_identity is required with token_format="handle". The Cred server issues a Delegation Token (a DPoP-bound JWT) to the agent's own key and accepts it only with a DPoP proof signed by that key. The key stays in your process; it is never sent to the model or the server, and it is not a tool argument. The model only sees delegation_id: the token itself is kept in an in-process map (delegation_id to token and expiry), filled by the delegate tool and read by the use tool, so it never appears in tool output. The use tool raises a clear error if no agent_identity is configured or the delegation_id is unknown or expired (call the delegate tool again). In a process that serves more than one user, pass user_id= to the use tool as well: a use tool configured with a user_id refuses delegations issued for any other user. Without it, the user is not checked.

When the user hasn't connected the service, the tool raises ConsentRequiredError. The error's consent_url attribute contains the URL to redirect the user.

from cred import ConsentRequiredError

try:
    result = await tool.run_json(
        {"service": "google", "scopes": ["calendar.readonly"]},
        cancellation_token,
    )
except ConsentRequiredError as e:
    print(f"Redirect user to: {e.consent_url}")

Brokered Server Mode

Point CRED_BASE_URL at your self-hosted @credninja/server deployment and set token_format="handle" when you want the agent to receive delegation ids instead of provider access tokens.

Metadata

Release files for cred-autogen 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cred-autogen 2.0.0
File Size Uploaded Provenance Actions
cred_autogen-2.0.0.tar.gz 12.6 kB Without provenance Details for cred_autogen-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cred-autogen 2.0.0
File Interpreter ABI Platform Actions
cred_autogen-2.0.0-py3-none-any.whl Python 3 none any Details for cred_autogen-2.0.0-py3-none-any.whl

Total release size: 22.7 kB

Release files / cred_autogen-2.0.0.tar.gz

Download URL cred_autogen-2.0.0.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
73141130d885602c99fe014dd09781d4bc82cae43a0d1bfc27c6770af69c59bb
BLAKE2b-256 checksum
How to use checksums
7538954b32d30eedb59f2ce36e30d1156ec5046712ff0703c334782c1b9cf938
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / cred_autogen-2.0.0-py3-none-any.whl

Download URL cred_autogen-2.0.0-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c5a08269c2498fda521defea59dfc4225799da9efa64912a25d0c70287151567
BLAKE2b-256 checksum
How to use checksums
1af798bfbc6033f7903a1e93f8e1aa6d0f5fdd0bae7ea5580a5e318c0834cb80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Security for cred-autogen 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page