Skip to main content

Agent Context

The AgentContext object provides runtime context and tool calling capabilities.

Overview

Every entrypoint receives a context parameter:

@entrypoint
async def main(input: dict, context: AgentContext):
# Use context here
pass

Properties

PropertyTypeDescription
run_idstrCurrent run ID
step_idstrCurrent step ID
lease_idstrCurrent lease ID
@entrypoint
async def main(input: dict, context: AgentContext):
print(f"Running: {context.run_id}")
print(f"Step: {context.step_id}")
print(f"Lease: {context.lease_id}")

Methods

call_tool()

Call a tool (local or platform):

async def call_tool(name: str, args: dict) -> any

Example:

result = await context.call_tool("structured_data_get", {
"namespace": "users",
"key": "user:123"
})

Platform Tool Access

Structured Data

# Save data
await context.call_tool("structured_data_save", {
"namespace": "my-app",
"key": "config:main",
"data": {"theme": "dark", "lang": "en"},
"metadata": {"type": "config"}
})

# Get data
config = await context.call_tool("structured_data_get", {
"namespace": "my-app",
"key": "config:main"
})

# Query by metadata
results = await context.call_tool("structured_data_query", {
"namespace": "my-app",
"filters": {"metadata.type": "config"}
})

# Delete
await context.call_tool("structured_data_delete", {
"namespace": "my-app",
"key": "config:main"
})

# List keys
keys = await context.call_tool("structured_data_list_keys", {
"namespace": "my-app",
"pattern": "config:*"
})

Local Tool Access

@tool
async def my_tool(arg: str):
return f"Processed: {arg}"

@entrypoint
async def main(input: dict, context: AgentContext):
result = await context.call_tool("my_tool", {"arg": "hello"})
# result: "Processed: hello"

Next Steps