Skip to main content

Overview

The agents client manages AI agent registrations. Each agent has a unique ID, a DID (Decentralized Identifier), a set of scopes it can request, and a lifecycle status. Access the agents client via client.agents.

Register

Register a new agent with a name and set of scopes:
from grantex import Grantex

with Grantex(api_key="gx_live_...") as client:
    agent = client.agents.register(
        name="travel-assistant",
        scopes=["booking:read", "booking:write", "profile:read"],
        description="Books flights and hotels on behalf of users",
    )

    print(f"Agent ID: {agent.id}")
    print(f"Agent DID: {agent.did}")
    print(f"Scopes: {agent.scopes}")

Parameters

ParameterTypeRequiredDefaultDescription
namestrYesHuman-readable name for the agent.
scopeslist[str]YesThe scopes this agent can request.
descriptionstrNo""A description of what the agent does.
All parameters are keyword-only.

Returns

An Agent dataclass.

Get

Retrieve a single agent by its ID:
agent = client.agents.get("agt_abc123")

print(f"Name: {agent.name}")
print(f"Status: {agent.status}")
print(f"Created: {agent.created_at}")

List

List all agents registered under your developer account:
result = client.agents.list()

print(f"Total agents: {result.total}")
for agent in result.agents:
    print(f"  {agent.name} ({agent.id}) - {agent.status}")

ListAgentsResponse

FieldTypeDescription
agentstuple[Agent, ...]The list of agents.
totalintTotal number of agents.
pageintCurrent page number.
page_sizeintNumber of agents per page.

Update

Update an agent’s name, description, or scopes. Only fields you provide will be modified:
updated = client.agents.update(
    "agt_abc123",
    name="travel-assistant-v2",
    description="Updated description",
    scopes=["booking:read", "booking:write", "profile:read", "profile:write"],
)

print(f"Updated at: {updated.updated_at}")

Parameters

ParameterTypeRequiredDescription
agent_idstrYesThe ID of the agent to update (positional).
namestr | NoneNoNew name for the agent.
descriptionstr | NoneNoNew description.
scopeslist[str] | NoneNoNew set of scopes.

Delete

Delete an agent by its ID:
client.agents.delete("agt_abc123")
# Returns None on success

Agent Type

The Agent frozen dataclass has the following fields:
FieldTypeDescription
idstrUnique agent identifier.
didstrDecentralized Identifier for the agent.
namestrHuman-readable agent name.
descriptionstrAgent description.
scopestuple[str, ...]Scopes this agent can request.
statusstrAgent status (e.g. "active").
developer_idstrID of the developer who owns this agent.
created_atstrISO 8601 creation timestamp.
updated_atstrISO 8601 last-updated timestamp.

Example: Full Lifecycle

from grantex import Grantex

with Grantex(api_key="gx_live_...") as client:
    # Register
    agent = client.agents.register(
        name="email-drafter",
        scopes=["email:draft", "email:send"],
        description="Drafts and sends emails",
    )
    print(f"Registered: {agent.id}")

    # Retrieve
    fetched = client.agents.get(agent.id)
    print(f"Name: {fetched.name}")

    # Update
    updated = client.agents.update(agent.id, name="email-assistant")
    print(f"Renamed to: {updated.name}")

    # List
    all_agents = client.agents.list()
    print(f"Total agents: {all_agents.total}")

    # Delete
    client.agents.delete(agent.id)
    print("Deleted")