In this lab, you'll learn how to call the Neo4j Aura Agent you created in Lab 2 programmatically using Python. This enables you to integrate your no-code Aura Agent into applications, scripts, and automated workflows.
Before starting, make sure you have:
- Completed Lab 0 (AWS sign-in)
- Completed Lab 1 (Neo4j Aura setup)
- Completed Lab 2 (Built an Aura Agent with tools)
- Completed Lab 4 (SageMaker setup)
In Lab 2, you built a powerful GraphRAG agent using Neo4j's visual agent builder. That agent can:
- Answer questions about SEC 10-K filings
- Use Cypher template tools to query company data
- Perform semantic similarity searches
- Generate Cypher queries from natural language
Now you'll learn to call that same agent via a REST API, enabling:
- Application Integration: Embed the agent in web apps, mobile apps, or microservices
- Automation: Include agent calls in data pipelines and workflows
- Batch Processing: Ask multiple questions programmatically
- Custom UIs: Build your own chat interfaces
- OAuth2 Authentication: How to authenticate with the Neo4j API
- API Invocation: How to call your Aura Agent's REST endpoint
- Response Parsing: How to extract text, thinking, and tool usage from responses
- Token Management: How to cache and refresh access tokens automatically
- Async Patterns: How to make concurrent requests for better performance
- Log in to Neo4j Aura Console
- Click your profile icon in the top right corner
- Go to Settings
- Select the API keys tab
- Click Create API Key
- Copy and save both the Client ID and Client Secret
Important: The Client Secret is only shown once. Save it securely!
- In the Aura Console, navigate to your agent
- Click on your agent to open its details
- Click the Copy endpoint button
- The URL will look like:
https://api.neo4j.io/v2beta1/organizations/.../projects/.../agents/.../invoke
Your agent must have External visibility to be called via API:
- Open your agent's settings
- Ensure External endpoint is enabled
This lab contains one comprehensive notebook:
Build and use a complete Python client to call your Aura Agent:
- Understand OAuth2 client credentials flow
- Create type-safe response models with Pydantic
- Build a reusable client class
- Test with sample questions about your SEC filing data
- Explore agent thinking and tool usage
- Make concurrent async requests
- Open the notebook:
aura_agent_client.ipynb - Paste your credentials in the Configuration section:
NEO4J_CLIENT_ID- Your API key Client IDNEO4J_CLIENT_SECRET- Your API key Client SecretNEO4J_AGENT_ENDPOINT- Your agent's endpoint URL
- Run through the notebook cells
The client handles authentication automatically:
1. Request Token
POST https://api.neo4j.io/oauth/token
- Basic Auth: client_id:client_secret
- Body: grant_type=client_credentials
→ Response: { access_token, expires_in: 3600 }
2. Invoke Agent
POST {agent_endpoint}/invoke
- Authorization: Bearer {access_token}
- Body: { input: "your question" }
→ Response: { content, status, usage }
Tokens are cached for 1 hour and automatically refreshed when expired.
After completing the notebook, you can call your agent like this:
# Create client
client = AuraAgentClient(
client_id="your-client-id",
client_secret="your-client-secret",
endpoint_url="https://api.neo4j.io/.../invoke"
)
# Ask a question
response = client.invoke("Tell me about Apple's risk factors")
print(response.text)
# View agent reasoning
print(response.thinking)
# Check tool usage
for tool in response.tool_uses:
print(f"Used tool: {tool.type}")Try these questions with your agent (same as Lab 2):
Company Overview:
- "Tell me about Apple Inc and their major investors"
- "What is NVIDIA's business and what risks do they face?"
Comparative Analysis:
- "What risks do Apple and Microsoft share?"
- "Compare the risk factors between tech companies"
Semantic Search:
- "What do the filings say about AI and machine learning?"
- "Find mentions of supply chain challenges"
Structured Queries:
- "Which company has the most risk factors?"
- "List all the products mentioned for Microsoft"
| Concept | Description |
|---|---|
| OAuth2 Client Credentials | Authentication flow for machine-to-machine API access |
| Bearer Token | Access token included in API request headers |
| Token Caching | Reusing tokens until they expire (1 hour) |
| Pydantic Models | Type-safe data validation for API responses |
| Async/Await | Python pattern for concurrent, non-blocking operations |
Congratulations! You have completed all labs in the workshop.
You now have hands-on experience with:
- Building no-code AI agents with Neo4j Aura Agents
- Building GraphRAG pipelines with the neo4j-graphrag library
- Connecting LLM agents to Neo4j via the Model Context Protocol
- Calling Aura Agents programmatically via REST API