-
Notifications
You must be signed in to change notification settings - Fork 16
feat: add spraay crypto payments agent example #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
plagtech
wants to merge
3
commits into
NVIDIA:main
Choose a base branch
from
plagtech:add-spraay-crypto-payments
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| <!-- | ||
| SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| --> | ||
|
|
||
| # Spraay Crypto Payments Agent | ||
|
|
||
| An AI agent that queries cryptocurrency data across 15 blockchains using the | ||
| [Spraay x402 gateway](https://gateway.spraay.app). The agent can check gateway | ||
| health, list supported chains and routes, look up wallet balances, and get | ||
| token prices - all through natural language. | ||
|
|
||
| ## Overview | ||
|
|
||
| This example demonstrates how to build a crypto query agent using NeMo | ||
| Agent Toolkit with custom tools that interact with the Spraay x402 protocol | ||
| gateway. The agent uses a ReAct pattern to reason about queries and execute | ||
| them via HTTP API calls. | ||
|
|
||
| ### What is x402? | ||
|
|
||
| The [x402 protocol](https://www.x402.org) enables AI agents to pay for API | ||
| services using USDC micropayments over HTTP. When an agent calls a paid | ||
| endpoint, the server returns HTTP 402 (Payment Required) with payment details. | ||
| The agent signs a USDC transaction, resends the request with payment proof, | ||
| and the server executes the operation. | ||
|
|
||
| ### Supported Chains | ||
|
|
||
| Base, Ethereum, Arbitrum, Polygon, BNB Chain, Avalanche, Solana, | ||
| Bitcoin, Stacks, Unichain, Plasma, BOB, Bittensor, Stellar, XRP Ledger. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Python 3.11+ | ||
| - [uv](https://docs.astral.sh/uv/) package manager | ||
| - NVIDIA API key from [build.nvidia.com](https://build.nvidia.com) | ||
|
|
||
| ## Setup | ||
|
|
||
| 1. Clone this repository and navigate to the example: | ||
|
|
||
| ```bash | ||
| cd examples/spraay_crypto_payments | ||
| ``` | ||
|
|
||
| 2. Install dependencies: | ||
|
|
||
| ```bash | ||
| uv pip install -e . | ||
| ``` | ||
|
|
||
| 3. Set environment variables: | ||
|
|
||
| ```bash | ||
| export NVIDIA_API_KEY=<your-nvidia-api-key> | ||
| export SPRAAY_GATEWAY_URL=https://gateway.spraay.app # optional, this is the default | ||
| ``` | ||
|
|
||
| ## Running the Example | ||
|
|
||
| ### Check gateway health | ||
|
|
||
| ```bash | ||
| nat run \ | ||
| --config_file configs/config.yml \ | ||
| --input "Is the Spraay gateway healthy?" | ||
| ``` | ||
|
|
||
| ### List supported chains | ||
|
|
||
| ```bash | ||
| nat run \ | ||
| --config_file configs/config.yml \ | ||
| --input "What blockchains does Spraay support?" | ||
| ``` | ||
|
|
||
| ### Get token price | ||
|
|
||
| ```bash | ||
| nat run \ | ||
| --config_file configs/config.yml \ | ||
| --input "What is the current price of ETH on Base?" | ||
| ``` | ||
|
|
||
| ## Expected Output | ||
|
|
||
| ``` | ||
| $ nat run --config_file configs/config.yml --input "Is the Spraay gateway healthy?" | ||
|
|
||
| Configuration Summary: | ||
| -------------------- | ||
| Workflow Type: react_agent | ||
| Number of Functions: 5 | ||
| Number of LLMs: 1 | ||
|
|
||
| Agent's thoughts: | ||
| Thought: The user wants to check if the Spraay gateway is healthy. | ||
| I should use the spraay_health tool. | ||
| Action: spraay_health | ||
| Action Input: check health | ||
|
|
||
| Observation: { | ||
| "status": "ok", | ||
| "version": "3.6.0", | ||
| "uptime": "..." | ||
| } | ||
|
|
||
| Thought: The gateway is healthy and running. | ||
| Final Answer: Yes, the Spraay x402 gateway is healthy. It is running | ||
| version 3.6.0 and reporting an "ok" status. | ||
| ------------------------------ | ||
| Workflow Result: ['Yes, the Spraay x402 gateway is healthy...'] | ||
| ``` | ||
|
|
||
| ## Architecture | ||
|
|
||
| ``` | ||
| NeMo Agent Toolkit | ||
| | | ||
| v | ||
| ReAct Agent (Llama 3.1) | ||
| | | ||
| +-- spraay_health | ||
| +-- spraay_routes | ||
| +-- spraay_chains | ||
| +-- spraay_balance | ||
| +-- spraay_price | ||
| | | ||
| v | ||
| HTTP + x402 | ||
| | | ||
| v | ||
| Spraay x402 Gateway (gateway.spraay.app) | ||
| - 84+ paid endpoints | ||
| - 15 blockchains | ||
| - USDC micropayments | ||
| ``` | ||
|
|
||
| ## Files | ||
|
|
||
| | File | Description | | ||
| |------|-------------| | ||
| | `configs/config.yml` | NeMo Agent Toolkit workflow configuration | | ||
| | `src/spraay_crypto_payments/register.py` | Tool registration with `@register_function` | | ||
| | `src/spraay_crypto_payments/spraay_client.py` | Async HTTP client for the Spraay gateway | | ||
| | `src/spraay_crypto_payments/__init__.py` | Package init | | ||
| | `pyproject.toml` | Project dependencies and NAT entry points | | ||
|
|
||
| ## Links | ||
|
|
||
| - [Spraay Gateway Docs](https://docs.spraay.app) | ||
| - [x402 Protocol](https://www.x402.org) | ||
| - [Spraay MCP Server](https://smithery.ai/server/@plagtech/spraay-x402-mcp) | ||
| - [NeMo Agent Toolkit Docs](https://docs.nvidia.com/nemo/agent-toolkit/latest/) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # Spraay Crypto Payments Agent | ||
| # NeMo Agent Toolkit workflow configuration | ||
| # | ||
| # This agent uses the Spraay x402 gateway to execute cryptocurrency | ||
| # payments across 15 blockchains via USDC micropayments. | ||
|
|
||
| functions: | ||
| # Free query tools (no x402 payment required) | ||
| spraay_health: | ||
| _type: spraay_gateway_tool | ||
| gateway_url: ${SPRAAY_GATEWAY_URL:-https://gateway.spraay.app} | ||
| endpoint: /health | ||
| method: GET | ||
| description: "Check the health status of the Spraay x402 gateway" | ||
|
|
||
| spraay_routes: | ||
| _type: spraay_gateway_tool | ||
| gateway_url: ${SPRAAY_GATEWAY_URL:-https://gateway.spraay.app} | ||
| endpoint: /v1/routes | ||
| method: GET | ||
| description: "List all available Spraay gateway routes with pricing info" | ||
|
|
||
| spraay_chains: | ||
| _type: spraay_gateway_tool | ||
| gateway_url: ${SPRAAY_GATEWAY_URL:-https://gateway.spraay.app} | ||
| endpoint: /v1/chains | ||
| method: GET | ||
| description: "List all supported blockchains on the Spraay gateway" | ||
|
|
||
| spraay_balance: | ||
| _type: spraay_balance_tool | ||
| gateway_url: ${SPRAAY_GATEWAY_URL:-https://gateway.spraay.app} | ||
| description: "Check the token balance of a wallet address on a specific chain" | ||
|
|
||
| spraay_price: | ||
| _type: spraay_price_tool | ||
| gateway_url: ${SPRAAY_GATEWAY_URL:-https://gateway.spraay.app} | ||
| description: "Get the current price of a token on a specific chain" | ||
|
|
||
| llms: | ||
| nim_llm: | ||
| _type: nim | ||
| model_name: meta/llama-3.1-70b-instruct | ||
| temperature: 0.0 | ||
|
|
||
| workflow: | ||
| _type: react_agent | ||
| tool_names: | ||
| - spraay_health | ||
| - spraay_routes | ||
| - spraay_chains | ||
| - spraay_balance | ||
| - spraay_price | ||
|
plagtech marked this conversation as resolved.
|
||
| llm_name: nim_llm | ||
| verbose: true | ||
| parse_agent_response_max_retries: 3 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| [project] | ||
| name = "spraay-crypto-payments" | ||
| version = "0.1.0" | ||
| description = "Spraay x402 crypto payment tools for NVIDIA NeMo Agent Toolkit" | ||
| readme = "README.md" | ||
| license = { text = "Apache-2.0" } | ||
| requires-python = ">=3.11,<3.14" | ||
| dependencies = [ | ||
| "nvidia-nat>=1.3.0", | ||
| "httpx>=0.27.0", | ||
| ] | ||
|
|
||
| [build-system] | ||
| requires = ["setuptools>=75.0"] | ||
| build-backend = "setuptools.build_meta" | ||
|
|
||
| [tool.setuptools.packages.find] | ||
| where = ["src"] | ||
|
|
||
| [project.entry-points.'nat.components'] | ||
| spraay_crypto_payments = "spraay_crypto_payments.register" |
14 changes: 14 additions & 0 deletions
14
examples/spraay_crypto_payments/src/spraay_crypto_payments/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.