### Run x402 Integration Tests (Real Chain) Source: https://github.com/agent0lab/agent0-ts/blob/main/tests/x402-server/README.md Execute integration tests against a real blockchain using Foundry and viem. This requires Foundry to be installed and on the PATH. It starts an anvil instance, deploys a mock token, and runs the SDK with a real signer. ```bash RUN_X402_ANVIL=1 npm test -- --testPathPattern=x402-anvil ``` ```bash npm run test:x402-anvil ``` -------------------------------- ### Install Agent0 SDK v0.31.0 Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.31.md Command to install the specific version of the agent0-sdk. ```bash npm install agent0-sdk@0.31.0 ``` -------------------------------- ### Install Agent0 SDK from Source Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Clones the Agent0 SDK repository and installs dependencies from source. Use this for development or contributing to the SDK. ```bash git clone https://github.com/agent0lab/agent0-ts.git cd agent0-ts npm install npm run build ``` -------------------------------- ### Install Agent0 SDK Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.2.4.md Command to install version 0.2.4 of the Agent0 SDK using npm. ```bash npm install agent0-sdk@0.2.4 ``` -------------------------------- ### Install Agent0 SDK v0.3.0-rc.1 Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.3rc1.md Install the specified release candidate version of the Agent0 SDK using npm. ```bash npm install agent0-sdk@0.3.0-rc.1 ``` -------------------------------- ### Install Agent0 SDK Source: https://context7.com/agent0lab/agent0-ts/llms.txt Install the Agent0 SDK using npm. Node.js version 22 or higher is required. ```bash npm install agent0-sdk # or pin a specific version npm install agent0-sdk@1.7.1 ``` -------------------------------- ### Install Agent0 SDK v0.2.3 Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.2.3.md Command to install version 0.2.3 of the Agent0 SDK using npm. ```bash npm install agent0-sdk@0.2.3 ``` -------------------------------- ### Run x402-a2a-demo Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_1.7.0.md Execute the demonstration for combined x402 and A2A functionalities. This example showcases pure x402 requests, A2A message/task flows, and combined A2A + x402 payment flows. ```bash npx tsx examples/x402-a2a-demo.ts ``` -------------------------------- ### Install Agent0 SDK via npm Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Installs the Agent0 SDK package using npm. Use this command for standard project integration. ```bash npm install agent0-sdk ``` -------------------------------- ### Install Specific Agent0 SDK Version via npm Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Installs a specific version of the Agent0 SDK package using npm. Useful for maintaining compatibility with older projects. ```bash npm install agent0-sdk@1.7.0 ``` -------------------------------- ### Install Agent0 SDK v0.2.2 Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.2.2.md Upgrade to the latest version of the Agent0 SDK using npm. This command ensures you have the most recent features and security patches. ```bash npm install agent0-sdk@0.2.2 ``` -------------------------------- ### OASF Skills and Domains in Registration File Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Example of how OASF skills and domains are represented within an agent's registration file. ```json { "endpoints": [ { "name": "OASF", "endpoint": "https://github.com/agntcy/oasf/", "version": "v0.8.0", "skills": [ "advanced_reasoning_planning/strategic_planning", "data_engineering/data_transformation_pipeline" ], "domains": [ "finance_and_business/investment_services", "technology/data_science/data_science" ] } ] } ``` -------------------------------- ### Initialize SDK with Ethers Signer Object Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.2.4.md Initialize the SDK with an Ethers Signer object, typically obtained from a browser provider like MetaMask. This requires an asynchronous operation to get the signer. ```typescript import { ethers } from 'ethers'; // Example: MetaMask or other browser provider const provider = new ethers.BrowserProvider(window.ethereum); const signer = await provider.getSigner(); const sdk = new SDK({ chainId: 11155111, rpcUrl: 'https://sepolia.infura.io/v3/YOUR_KEY', signer: signer, // Signer object }); ``` -------------------------------- ### Initialize Agent0 SDK (Server-Side) Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Initializes the Agent0 SDK with specified chain ID, RPC URL, private key, IPFS configuration, and Pinata JWT. This setup is for server-side operations and write capabilities. ```typescript import { SDK } from 'agent0-sdk'; // Initialize SDK with IPFS and subgraph const sdk = new SDK({ chainId: 11155111, // Ethereum Sepolia testnet (use 1 for Ethereum Mainnet) rpcUrl: process.env.RPC_URL, // Optional for supported chains (built-in default RPC is used if omitted) privateKey: process.env.PRIVATE_KEY ?? process.env.AGENT_PRIVATE_KEY, // Optional: for write operations ipfs: 'pinata', // Options: 'pinata', 'filecoinPin', 'node' (Kubo daemon), 'helia' (embedded) pinataJwt: process.env.PINATA_JWT // For Pinata // Subgraph URL auto-defaults from DEFAULT_SUBGRAPH_URLS }); ``` -------------------------------- ### OASF Endpoint in Agent Registration File Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.31.md Example JSON structure for an agent's registration file, showcasing the OASF endpoint configuration with skills and domains. ```json { "type": "https://eips.ethereum.org/EIPS/eip-8004#registration-v1", "name": "My AI Agent", "description": "An intelligent assistant for various tasks", "endpoints": [ { "name": "OASF", "endpoint": "https://github.com/agntcy/oasf/", "version": "v0.8.0", "skills": [ "advanced_reasoning_planning/strategic_planning", "data_engineering/data_transformation_pipeline", "natural_language_processing/natural_language_generation/summarization" ], "domains": [ "finance_and_business/investment_services", "technology/data_science/data_visualization", "technology/software_engineering" ] } ] } ``` -------------------------------- ### Initialize and Register Agent with OASF Capabilities Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.31.md Demonstrates initializing the SDK, creating an agent, adding OASF skills and domains with validation, and registering the agent. Ensure RPC_URL and PRIVATE_KEY environment variables are set. ```typescript import { SDK } from 'agent0-sdk'; // Initialize SDK const sdk = new SDK({ chainId: 11155111, rpcUrl: process.env.RPC_URL!, signer: process.env.PRIVATE_KEY }); // Create agent const agent = sdk.createAgent( 'Data Analyst Pro', 'A specialized AI agent for data analysis and visualization' ); // Add OASF skills and domains with validation agent .addSkill('data_engineering/data_transformation_pipeline', true) .addSkill('tabular_text/tabular_regression', true) .addSkill('multi_modal/image_processing/text_to_image', true) .addDomain('finance_and_business/investment_services', true) .addDomain('technology/data_science/data_visualization', true); // Register agent await agent.registerIPFS(); console.log(`Agent registered with OASF capabilities: ${agent.agentId}`); ``` -------------------------------- ### Initialize SDK with Private Key String Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.2.4.md Use this method to initialize the SDK with a private key string. This is the original and backward-compatible method. ```typescript const sdk = new SDK({ chainId: 11155111, rpcUrl: 'https://sepolia.infura.io/v3/YOUR_KEY', signer: '0x1234...', // Private key as string }); ``` -------------------------------- ### Initialize SDK with Browser Wallet (ERC-6963) Source: https://context7.com/agent0lab/agent0-ts/llms.txt Initialize the SDK for browser use by discovering ERC-6963 compliant wallet providers and connecting via EIP-1193. This allows signing transactions using a user's injected wallet. ```typescript import { SDK } from 'agent0-sdk'; import { discoverEip6963Providers, connectEip1193 } from 'agent0-sdk/eip6963'; // Discover all injected wallet providers const providers = await discoverEip6963Providers({ timeoutMs: 250 }); if (providers.length === 0) throw new Error('No injected wallets found'); // Select a wallet and request account access const selected = providers[0]; const { account } = await connectEip1193(selected.provider, { requestAccounts: true }); console.log(`Connected: ${selected.info.name} → ${account}`); // Initialize SDK with EIP-1193 provider for browser signing const sdk = new SDK({ chainId: 11155111, rpcUrl: 'https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY', walletProvider: selected.provider, // Signs txs via wallet popup }); ``` -------------------------------- ### Initialize SDK in Browser with ERC-6963 Wallets Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Initializes the Agent0 SDK in a browser environment, discovering and connecting to EIP-6963 compatible wallets for transaction signing. Ensure you replace 'YOUR_PROJECT_ID' with your actual Infura Project ID. ```typescript import { SDK } from 'agent0-sdk'; import { discoverEip6963Providers, connectEip1193 } from 'agent0-sdk/eip6963'; const providers = await discoverEip6963Providers(); if (providers.length === 0) throw new Error('No injected wallets found'); // Pick a wallet (UI selection recommended) const { provider } = providers[0]; await connectEip1193(provider); // prompts user const sdk = new SDK({ chainId: 11155111, rpcUrl: 'https://sepolia.infura.io/v3/YOUR_PROJECT_ID', walletProvider: provider, }); ``` -------------------------------- ### Prepare and Submit Off-Chain Feedback Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Use `prepareFeedbackFile` for rich feedback fields like text descriptions or tools used. Then, submit feedback using `giveFeedback`, optionally including the prepared file and on-chain fields. ```typescript const feedbackFile = sdk.prepareFeedbackFile({ text: 'Great agent!', mcpTool: 'code_generation', a2aSkills: ['python'], a2aContextId: 'session:abc', }); ``` ```typescript const tx = await sdk.giveFeedback( '11155111:123', 85, // value (number|string) 'data_analyst', // tag1 (optional) 'finance', // tag2 (optional) 'https://api.example.com/feedback', // endpoint (optional on-chain) feedbackFile // optional off-chain file ); const { receipt, result: feedback } = await tx.waitConfirmed(); ``` -------------------------------- ### Get Agent by ID Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Retrieves a specific agent using its chain-agnostic ID. ```APIDOC ## Get Agent ### Description Retrieves a specific agent using its chain-agnostic ID. ### Method `sdk.getAgent(agentId)` ### Parameters #### Path Parameters - **agentId** (string) - Required - The chain-agnostic ID of the agent (e.g., 'chainId:agentId'). ### Request Example ```typescript // Get agent from specific chain const agent = await sdk.getAgent('1:123'); // Ethereum Mainnet ``` ``` -------------------------------- ### Initialize SDK with Ethers Wallet Object Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.2.4.md Initialize the SDK using an Ethers Wallet object. Ensure you have imported the 'ethers' library. ```typescript import { ethers } from 'ethers'; const wallet = new ethers.Wallet('0x1234...'); const sdk = new SDK({ chainId: 11155111, rpcUrl: 'https://sepolia.infura.io/v3/YOUR_KEY', signer: wallet, // Wallet object }); ``` -------------------------------- ### Get Reputation Summary Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Retrieves a summary of an agent's reputation on a specific chain. ```APIDOC ## Get Reputation Summary ### Description Retrieves a summary of an agent's reputation on a specific chain. ### Method `sdk.getReputationSummary(agentId)` ### Parameters #### Path Parameters - **agentId** (string) - Required - The ID of the agent (e.g., 'chainId:agentId' or just 'agentId' for the default chain). ### Response #### Success Response (200) - **averageValue** (number) - The average reputation value for the agent. ### Request Example ```typescript // Get reputation summary for agent on specific chain const summary = await sdk.getReputationSummary('1:123'); // Ethereum Mainnet console.log(`Average value: ${summary.averageValue}`); // Get reputation summary using the default chain const summaryDefault = await sdk.getReputationSummary('1234'); ``` ``` -------------------------------- ### Remove Domain from OASF Endpoint (TypeScript) Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.31.md Example of removing a domain from an agent's OASF endpoint using its slug. ```typescript agent.removeDomain('finance_and_business/investment_services'); ``` -------------------------------- ### Create and Configure an Agent Source: https://context7.com/agent0lab/agent0-ts/llms.txt Use `sdk.createAgent` to initialize an agent object. Configure its endpoints, identity, trust models, and skills before activation and registration. Ensure all necessary configurations are set before calling `setActive`. ```typescript const agent = sdk.createAgent( 'Finance AI Agent', 'An agent specializing in financial analysis and reporting. Skills: data analysis, balance sheet review.', 'https://cdn.example.com/agent-icon.png' // Optional image URI ); // Configure endpoints (auto-fetches capabilities from live URLs) await agent.setMCP('https://mcp.example.com/', '2025-06-18'); // fetches tools/prompts/resources await agent.setA2A('https://a2a.example.com/.well-known/agent-card.json', '0.30'); // fetches skills // Set identity endpoints agent.setENS('financeai.eth'); // Trust models agent.setTrust( true, // reputation true, // crypto-economic false // tee-attestation ); // x402 payment support flag agent.setX402Support(true); // OASF taxonomies (validateOASF=true throws if slug is not in the local taxonomy bundle) agent.addSkill('data_engineering/data_transformation_pipeline', true); agent.addSkill('natural_language_processing/natural_language_generation/summarization', true); agent.addDomain('finance_and_business/investment_services', true); agent.addDomain('technology/data_science/data_science', true); // Custom metadata agent.setMetadata({ version: '1.0.0', pricing: '0.01', category: 'finance' }); // Activate agent.setActive(true); console.log(agent.name); // 'Finance AI Agent' console.log(agent.mcpEndpoint); // 'https://mcp.example.com/' console.log(agent.a2aSkills); // string[] from auto-fetch ``` -------------------------------- ### Remove Skill from OASF Endpoint (TypeScript) Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.31.md Example of removing a skill from an agent's OASF endpoint using its slug. ```typescript agent.removeSkill('advanced_reasoning_planning/strategic_planning'); ``` -------------------------------- ### Initialize SDK for Server-Side Operations Source: https://context7.com/agent0lab/agent0-ts/llms.txt Initialize the SDK for server-side use with private key signing and IPFS integration. Supports default RPC URLs for Ethereum, Base, and Polygon, with optional configuration for custom subgraphs and RPC endpoints. ```typescript import { SDK } from 'agent0-sdk'; // Server-side with Pinata IPFS const sdk = new SDK({ chainId: 11155111, // Ethereum Sepolia rpcUrl: process.env.RPC_URL, // Optional for supported chains privateKey: process.env.PRIVATE_KEY, // Hex private key for write operations ipfs: 'pinata', // 'pinata' | 'filecoinPin' | 'helia' | 'node' pinataJwt: process.env.PINATA_JWT, subgraphOverrides: {}, // Optional custom subgraph URLs per chain overrideRpcUrls: { // Per-chain RPC overrides (for x402 on other chains) 8453: 'https://base.drpc.org', }, registrationDataUriMaxBytes: 256 * 1024, // Max on-chain data URI size (default 256 KiB) }); // Read-only (no signer) const readOnlySdk = new SDK({ chainId: 11155111 }); console.log(readOnlySdk.isReadOnly); // true // Multi-chain with x402 support (Base Sepolia + Base Mainnet) const multiSdk = new SDK({ chainId: 84532, privateKey: process.env.PRIVATE_KEY, overrideRpcUrls: { 84532: 'https://base-sepolia.drpc.org', 8453: 'https://base.drpc.org', }, }); ``` -------------------------------- ### Get Subgraph Client Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.3rc1.md Obtains a subgraph client instance for interacting with subgraph data. Can be used for the default chain or a specific chain ID. ```typescript const client = sdk.getSubgraphClient(); ``` ```typescript const baseClient = sdk.getSubgraphClient(84532); ``` -------------------------------- ### OASF Endpoint Structure in Registration File Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.31.md Example of how the OASF endpoint is represented within an agent's registration file, including skills and domains. ```APIDOC ## OASF Endpoint Structure in Registration File ### Description This section illustrates the structure of an OASF endpoint within an agent's registration file. It details the fields used to define the agent's capabilities, such as skills and domains, according to the OASF specification. ### Fields - **`name`** (string) - Required - Always set to `"OASF"` to identify this endpoint type. - **`endpoint`** (string) - Required - The URL for the OASF specification, typically `"https://github.com/agntcy/oasf/"`. - **`version`** (string) - Required - The version of the OASF taxonomy used, e.g., `"v0.8.0"`. - **`skills`** (array of strings) - Optional - An array of skill slugs defined by the OASF taxonomy that the agent possesses. - **`domains`** (array of strings) - Optional - An array of domain slugs defined by the OASF taxonomy that the agent operates within. ### Example Registration File Snippet ```json { "type": "https://eips.ethereum.org/EIPS/eip-8004#registration-v1", "name": "My AI Agent", "description": "An intelligent assistant for various tasks", "endpoints": [ { "name": "OASF", "endpoint": "https://github.com/agntcy/oasf/", "version": "v0.8.0", "skills": [ "advanced_reasoning_planning/strategic_planning", "data_engineering/data_transformation_pipeline", "natural_language_processing/natural_language_generation/summarization" ], "domains": [ "finance_and_business/investment_services", "technology/data_science/data_visualization", "technology/software_engineering" ] } ] } ``` ``` -------------------------------- ### Run x402 Integration Tests (Server-only) Source: https://github.com/agent0lab/agent0-ts/blob/main/tests/x402-server/README.md Execute integration tests for the x402 server with mock payment verification. This command uses npm test with a specific test path pattern. ```bash RUN_X402_INTEGRATION=1 npm test -- --testPathPattern=x402-integration ``` ```bash npm run test:x402-integration ``` -------------------------------- ### Get Agent Reputation Summary Source: https://context7.com/agent0lab/agent0-ts/llms.txt Retrieves aggregated reputation statistics (count and average value) from the on-chain reputation registry for a specific agent. Can be filtered by tag. ```typescript // Overall reputation const overall = await sdk.getReputationSummary('11155111:42'); console.log(`Reviews: ${overall.count}, Average: ${overall.averageValue}`); ``` ```typescript // Reputation filtered by tag const tagRep = await sdk.getReputationSummary('11155111:42', 'data_analyst'); console.log(`data_analyst reviews: ${tagRep.count}, avg: ${tagRep.averageValue}`); ``` -------------------------------- ### Configure IPFS Storage Options Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Initialize the SDK with different IPFS configurations, including Filecoin Pin, embedded Helia, a local IPFS node, or Pinata. An HTTP registration option is also available for agents without IPFS. ```typescript const sdk = new SDK({ chainId: 11155111, rpcUrl: '...', signer: privateKey, ipfs: 'filecoinPin', filecoinPrivateKey: 'your-filecoin-private-key' }); ``` ```typescript const sdk = new SDK({ chainId: 11155111, rpcUrl: '...', signer: privateKey, ipfs: 'helia', }); ``` ```typescript const sdk = new SDK({ chainId: 11155111, rpcUrl: '...', signer: privateKey, ipfs: 'node', ipfsNodeUrl: 'http://localhost:5001' }); ``` ```typescript const sdk = new SDK({ chainId: 11155111, rpcUrl: '...', signer: privateKey, ipfs: 'pinata', pinataJwt: 'your-pinata-jwt-token' }); ``` ```typescript const sdk = new SDK({ chainId: 11155111, rpcUrl: '...', signer: privateKey }); const regTx = await agent.registerHTTP('https://example.com/agent-registration.json'); await regTx.waitConfirmed(); ``` -------------------------------- ### Get Agent Reputation Summary Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.3rc1.md Fetches the reputation summary for an agent, including feedback count and average score. Can query on the default chain or a specified chain. ```typescript const summary = await sdk.getReputationSummary('1234'); ``` ```typescript const summary = await sdk.getReputationSummary('84532:1234'); // Base Sepolia ``` -------------------------------- ### sdk.request() / sdk.fetchWithX402() Source: https://context7.com/agent0lab/agent0-ts/llms.txt Performs an HTTP request with automatic x402 (HTTP 402 Payment Required) handling. On 2xx returns the parsed result; on 402 returns `{ x402Required: true, x402Payment }` — no exception is thrown. ```APIDOC ## sdk.request() / sdk.fetchWithX402() Performs an HTTP request with automatic x402 (HTTP 402 Payment Required) handling. On 2xx returns the parsed result; on 402 returns `{ x402Required: true, x402Payment }` — no exception is thrown. ```typescript import { isX402Required } from 'agent0-sdk'; // GET a payment-required API const result = await sdk.request<{ tweets: unknown[] }>({ url: 'https://twitter.x402.agentbox.fyi/search?q=AI&limit=5', method: 'GET', }); if (isX402Required(result)) { // Inspect options console.log('Payment required. Options:', result.x402Payment.accepts); // Pay with first EVM option const data = await result.x402Payment.pay(0); console.log(data.tweets); } else { console.log(result.tweets); } // POST with payment header pre-attached const postResult = await sdk.request({ url: 'https://api.example.com/generate', method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ prompt: 'Summarize this.' }), parseResponse: (res) => res.json() as Promise<{ text: string }>, }); if (!postResult.x402Required) { console.log(postResult.text); } // Pay using payFirst() (auto-selects chain with sufficient balance) if (isX402Required(result)) { const data = await result.x402Payment.payFirst?.(); console.log(data); } ``` ``` -------------------------------- ### Get Single Agent Summary Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Retrieves a read-only summary of a single agent, which is faster than loading the full agent object. Supports the 'chainId:agentId' format for specifying the agent. ```typescript // Get single agent (read-only, faster) // Supports chainId:agentId format const agentSummary = await sdk.getAgent('11155111:123'); // explicit chainId:agentId ``` -------------------------------- ### Create and Register Agent Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Creates a new agent, configures its endpoints (MCP, A2A), sets ENS, adds OASF skills and domains, optionally sets a dedicated agent wallet, and registers the agent on-chain via IPFS. Ensure you have the necessary private key if setting a new wallet. ```typescript // Create agent const agent = sdk.createAgent( 'My AI Agent', 'An intelligent assistant for various tasks. Skills: data analysis, code generation.', 'https://example.com/agent-image.png' ); // Configure endpoints (automatically extracts capabilities) await agent.setMCP('https://mcp.example.com/'); // Extracts tools, prompts, resources await agent.setA2A('https://a2a.example.com/agent-card.json'); // Extracts skills agent.setENS('myagent.eth'); // Add OASF skills and domains (standardized taxonomies) agent.addSkill('data_engineering/data_transformation_pipeline', true); agent.addSkill('natural_language_processing/natural_language_generation/summarization', true); agent.addDomain('finance_and_business/investment_services', true); agent.addDomain('technology/data_science/data_science', true); // Optionally set a dedicated agent wallet on-chain (requires new wallet signature). // If you want agentWallet = owner wallet, you can skip this (contract sets initial value to owner). // await agent.setWallet('0x...', { newWalletPrivateKey: process.env.NEW_WALLET_PRIVATE_KEY }); agent.setTrust(true, true, false); // reputation, cryptoEconomic, teeAttestation // Add metadata and set status agent.setMetadata({ version: '1.0.0', category: 'ai-assistant' }); agent.setActive(true); // Register on-chain with IPFS const registrationFile = await agent.registerIPFS(); console.log(`Agent registered: ${registrationFile.agentId}`); // e.g., "11155111:123" console.log(`Agent URI: ${registrationFile.agentURI}`); // e.g., "ipfs://Qm..." ``` -------------------------------- ### Chain-Agnostic Agent ID Usage Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Examples demonstrating how to use chain-agnostic agent IDs in the format 'chainId:agentId' to interact with agents on specific or default chains for retrieval and feedback. ```typescript const agent = await sdk.getAgent('1:1234'); // Ethereum Mainnet ``` ```typescript const feedbacks = await sdk.searchFeedback({ agentId: '1:1234' }); // Ethereum Mainnet ``` ```typescript const feedbacksDefault = await sdk.searchFeedback({ agentId: '11155111:1234' }); // Default chain ``` ```typescript const summary = await sdk.getReputationSummary('1:1234'); // Ethereum Mainnet ``` ```typescript const summaryDefault = await sdk.getReputationSummary('1234'); // Uses default chain ``` -------------------------------- ### SDK Initialization with Default Chain Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.3rc1.md Demonstrates how to initialize the SDK and set a default chain for subsequent operations. The default chain is used when an agent ID is not prefixed with a chain ID or when functions are called without explicit chain parameters. ```APIDOC ## SDK Initialization ### Description Initialize the SDK with a default chain ID and RPC URL. This default chain will be used for operations where a specific chain is not explicitly provided. ### Method `new SDK(config: { chainId: number; rpcUrl: string })` ### Parameters - **config.chainId** (number) - Required - The chain ID to be set as the default. - **config.rpcUrl** (string) - Required - The RPC endpoint URL for the default chain. ### Request Example ```typescript import { SDK } from 'agent0-sdk'; // Initialize SDK with Ethereum Sepolia as default chain const sdk = new SDK({ chainId: 11155111, // This becomes the default chain rpcUrl: 'https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY' }); ``` ``` -------------------------------- ### Method Chaining Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.31.md Demonstrates how multiple OASF management methods can be chained together for efficient configuration. ```APIDOC ## Method Chaining ### Description All methods for managing OASF skills and domains (`addSkill`, `addDomain`, `removeSkill`, `removeDomain`) support method chaining. This allows for a more concise and fluent way to configure the agent's capabilities. ### Usage Example ```typescript agent .addSkill('data_engineering/data_transformation_pipeline', true) .addDomain('technology/data_science', true) .addSkill('natural_language_processing/summarization', true) .removeSkill('old_skill'); ``` ``` -------------------------------- ### Run x402 Test Server Source: https://github.com/agent0lab/agent0-ts/blob/main/tests/x402-server/README.md Execute the x402 test server using Node.js. Can be run with custom port and accepts JSON configurations via environment variables. ```bash node tests/x402-server/server.mjs ``` ```bash PORT=4021 node tests/x402-server/server.mjs ACCEPTS_JSON='[{"price":"1000000","token":"0xToken","network":"84532","destination":"0xPayTo"}]' node tests/x402-server/server.mjs ``` -------------------------------- ### IPFS Configuration Options Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Illustrates different ways to configure IPFS integration within the SDK, including Filecoin Pin, Helia, IPFS Node, and Pinata. ```APIDOC ## IPFS Configuration Options ### Description Configures the SDK's IPFS integration using various providers. ### Method `new SDK(options)` ### Parameters #### Request Body - **chainId** (number) - Required - The chain ID. - **rpcUrl** (string) - Required - The RPC URL. - **signer** (any) - Required - The signer object. - **ipfs** (string) - Optional - The IPFS integration type ('filecoinPin', 'helia', 'node', 'pinata', or omitted for no IPFS). - **filecoinPrivateKey** (string) - Optional - Required if `ipfs` is 'filecoinPin'. - **ipfsNodeUrl** (string) - Optional - Required if `ipfs` is 'node'. - **pinataJwt** (string) - Optional - Required if `ipfs` is 'pinata'. ### Request Example ```typescript // Option 1: Filecoin Pin const sdkFilecoin = new SDK({ chainId: 11155111, rpcUrl: '...', signer: privateKey, ipfs: 'filecoinPin', filecoinPrivateKey: 'your-filecoin-private-key' }); // Option 2: Embedded Helia const sdkHelia = new SDK({ chainId: 11155111, rpcUrl: '...', signer: privateKey, ipfs: 'helia', }); // Option 3: IPFS Node (Kubo) const sdkNode = new SDK({ chainId: 11155111, rpcUrl: '...', signer: privateKey, ipfs: 'node', ipfsNodeUrl: 'http://localhost:5001' }); // Option 4: Pinata const sdkPinata = new SDK({ chainId: 11155111, rpcUrl: '...', signer: privateKey, ipfs: 'pinata', pinataJwt: 'your-pinata-jwt-token' }); // Option 5: HTTP registration (no IPFS) const sdkHttp = new SDK({ chainId: 11155111, rpcUrl: '...', signer: privateKey }); ``` ``` -------------------------------- ### Get Agent with Chain Specification Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.3rc1.md Demonstrates retrieving a single agent by ID, showing how to use the SDK's default chain or explicitly specify a different chain using the `chainId:agentId` format. ```typescript // Using default chain const agent = await sdk.getAgent('1234'); // Uses SDK's default chain // Explicitly specify chain const agent = await sdk.getAgent('84532:1234'); // Base Sepolia const agent = await sdk.getAgent('80002:5678'); // Polygon Amoy ``` -------------------------------- ### Get Agent using Default and Explicit Chains Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.3rc1.md Retrieve an agent using its ID. The SDK defaults to the initialized chain if only an agent ID is provided, or uses the specified chain when a `chainId:agentId` format is used. ```typescript // Uses default chain (11155111) const agent = await sdk.getAgent('1234'); // Equivalent to "11155111:1234" // Explicitly specify a different chain const agent = await sdk.getAgent('84532:1234'); // Base Sepolia ``` -------------------------------- ### Prepare Feedback File Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Prepares an off-chain feedback file, which is necessary for including rich fields like text, tools, and skills. ```APIDOC ## Prepare Feedback File ### Description Prepares an off-chain feedback file for rich feedback fields. ### Method `sdk.prepareFeedbackFile(options)` ### Parameters #### Request Body - **text** (string) - Optional - Textual feedback. - **mcpTool** (string) - Optional - The MCP tool used. - **a2aSkills** (string[]) - Optional - Skills utilized by the agent. - **a2aContextId** (string) - Optional - Context ID for the agent-to-agent interaction. ### Request Example ```typescript const feedbackFile = sdk.prepareFeedbackFile({ text: 'Great agent!', mcpTool: 'code_generation', a2aSkills: ['python'], a2aContextId: 'session:abc', }); ``` ``` -------------------------------- ### Get Agent Using Default or Explicit Chain Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Retrieve an agent using its ID. If no chain prefix is provided, the agent is fetched from the SDK's default chain. An explicit chain ID prefix can be used to fetch from a different chain. ```typescript // Uses default chain (11155111) const agent = await sdk.getAgent('1234'); // Equivalent to "11155111:1234" ``` ```typescript // Explicitly specify different chain const agent = await sdk.getAgent('1:1234'); // Ethereum Mainnet ``` -------------------------------- ### Run All Unit Tests Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_1.7.0.md Execute all unit tests for the project. This command is useful for a comprehensive check of the codebase. ```bash npm test ``` -------------------------------- ### SDK Initialization and Default Chain Behavior Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Configure the SDK with a default chain and optionally override RPC URLs. Agent IDs without a chain prefix will use the default chain. ```APIDOC ## SDK Initialization and Default Chain Behavior ### Description Initialize the SDK with a default chain and manage RPC URL configurations. ### Method `new SDK({ chainId: number, rpcUrl?: string })` ### Parameters #### Constructor Parameters - **chainId** (number) - Required - The default chain ID for the SDK instance. - **rpcUrl** (string) - Optional - An override for the default RPC URL. If omitted for a supported chain, a built-in default is used. ### Default Chain Behavior Agent IDs without a `chainId:` prefix will use the default chain specified during SDK initialization. ### Request Example ```typescript const sdk = new SDK({ chainId: 11155111, // Default chain; rpcUrl optional (built-in default used) rpcUrl: 'https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY' // optional override }); // Uses default chain (11155111) const agent = await sdk.getAgent('1234'); // Equivalent to "11155111:1234" // Explicitly specify different chain const agent = await sdk.getAgent('1:1234'); // Ethereum Mainnet ``` ``` -------------------------------- ### Initialize SDK with Default Chain Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.3rc1.md Initialize the SDK with a default chain ID and RPC URL. This default chain is used when no specific chain is provided in subsequent calls. ```typescript import { SDK } from 'agent0-sdk'; // Initialize SDK with Ethereum Sepolia as default chain const sdk = new SDK({ chainId: 11155111, // This becomes the default chain rpcUrl: 'https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY' }); ``` -------------------------------- ### Prepare Feedback File Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_1.0.2.md Helper function to prepare a feedback file object, which can include text, context, capability, and name. This is used for off-chain feedback storage. ```typescript const feedbackFile = sdk.prepareFeedbackFile({ text: 'optional', context: { sessionId: 'abc' }, capability: 'tools', name: 'my_tool', }); ``` -------------------------------- ### Create A2A Client from Agent or Summary Source: https://context7.com/agent0lab/agent0-ts/llms.txt Use `createA2AClient` to instantiate an A2A-capable client. It accepts either a loaded `Agent` object or an `AgentSummary` from search results, allowing for interchangeable treatment of both. ```typescript import { A2AClientFromSummary } from 'agent0-sdk'; // From search result (AgentSummary) const [summary] = await sdk.searchAgents({ hasA2A: true, active: true }); const client = sdk.createA2AClient(summary); // returns A2AClientFromSummary const response = await client.messageA2A('Hello from search result.'); console.log(JSON.stringify(response, null, 2)); // From a loaded Agent (returns the Agent itself) const agent = await sdk.loadAgent('84532:1298'); const sameAgent = sdk.createA2AClient(agent); // returns the Agent as-is ``` -------------------------------- ### Feedback API (New Signature and Helper) Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_1.0.2.md The feedback API has been simplified for direct submission of on-chain fields. A new helper function `prepareFeedbackFile` is introduced for creating feedback files. ```APIDOC ## Give Feedback ### Description Submit feedback for an agent, including optional on-chain and off-chain details. ### Method `giveFeedback(agentId, score, tag1?, tag2?, endpoint?, feedbackFile?) ### Parameters - **agentId** (string) - Required - The ID of the agent to give feedback for. - **score** (number) - Required - The feedback score. - **tag1** (string) - Optional - The first feedback tag. - **tag2** (string) - Optional - The second feedback tag. - **endpoint** (string) - Optional - An on-chain endpoint for the feedback. - **feedbackFile** (object) - Optional - Off-chain file content for the feedback. ### Request Example ```ts const tx = await sdk.giveFeedback( agentId, score, tag1, tag2, endpoint, feedbackFile ); const { receipt, result: feedback } = await tx.waitConfirmed(); ``` ## Prepare Feedback File ### Description Helper function to prepare an off-chain feedback file object. ### Method `prepareFeedbackFile(data) ### Parameters #### Data Object - **text** (string) - Optional - Textual feedback content. - **context** (object) - Optional - Contextual information for the feedback. - **sessionId** (string) - Required - Session ID. - **capability** (string) - Optional - The capability the feedback relates to. - **name** (string) - Optional - The name associated with the feedback. ### Request Example ```ts const feedbackFile = sdk.prepareFeedbackFile({ text: 'optional', context: { sessionId: 'abc' }, capability: 'tools', name: 'my_tool', }); ``` ``` -------------------------------- ### Multi-Chain Search Agents Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Demonstrates how to search for agents across multiple specified chains or all configured chains. It also shows how to search agents based on feedback-derived reputation. ```APIDOC ## Search Agents ### Description Searches for agents across multiple chains or all configured chains. Can also filter by feedback-derived reputation. ### Method `sdk.searchAgents(options)` ### Parameters #### Query Parameters - **active** (boolean) - Optional - Filter for active agents. - **chains** (number[] | 'all') - Required - An array of chain IDs or 'all' to search across all configured chains. - **feedback** (object) - Optional - Filter agents based on feedback reputation. - **minValue** (number) - Required - The minimum feedback value. - **includeRevoked** (boolean) - Optional - Whether to include revoked feedback. ### Request Example ```typescript // Search across multiple chains const results = await sdk.searchAgents({ active: true, chains: [1, 11155111, 137] // Ethereum Mainnet, Ethereum Sepolia, Polygon Mainnet }); // Search all configured chains const allResults = await sdk.searchAgents({ active: true, chains: 'all' // Searches all configured chains }); // Search agents by feedback-derived reputation across chains (unified search) const reputationResults = await sdk.searchAgents( { chains: [1, 11155111, 137], feedback: { minValue: 80, includeRevoked: false } } ); ``` ``` -------------------------------- ### Method Chaining for OASF Configuration (TypeScript) Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.31.md Illustrates how to chain multiple `addSkill`, `addDomain`, and `removeSkill` calls for efficient agent OASF configuration. ```typescript agent .addSkill('data_engineering/data_transformation_pipeline', true) .addDomain('technology/data_science', true) .addSkill('natural_language_processing/summarization', true) .removeSkill('old_skill'); ``` -------------------------------- ### Run Agent0 SDK Multi-Chain Tests Source: https://github.com/agent0lab/agent0-ts/blob/main/release_notes/RELEASE_NOTES_0.3rc1.md Execute the comprehensive test suite for multi-chain functionality using npm. This command specifically targets the multi-chain test file. ```bash npm test -- tests/multi-chain.test.ts ``` -------------------------------- ### Initialize SDK with Default Chain and RPC Override Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Initialize the SDK with a default chain ID. RPC URLs can be overridden using `rpcUrl` for the primary chain or `overrideRpcUrls` for specific chains. Built-in defaults are used if not provided. ```typescript const sdk = new SDK({ chainId: 11155111, // Default chain; rpcUrl optional (built-in default used) rpcUrl: 'https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY' // optional override }); ``` -------------------------------- ### sdk.createA2AClient() Source: https://context7.com/agent0lab/agent0-ts/llms.txt Creates an A2A-capable client from either a loaded Agent or an AgentSummary. This is useful for treating both interchangeably when you only have a summary from search results. ```APIDOC ## sdk.createA2AClient() Creates an A2A-capable client from either a loaded `Agent` or an `AgentSummary`. Useful for treating both interchangeably when you only have a summary from search results. ```typescript import { A2AClientFromSummary } from 'agent0-sdk'; // From search result (AgentSummary) const [summary] = await sdk.searchAgents({ hasA2A: true, active: true }); const client = sdk.createA2AClient(summary); // returns A2AClientFromSummary const response = await client.messageA2A('Hello from search result.'); console.log(JSON.stringify(response, null, 2)); // From a loaded Agent (returns the Agent itself) const agent = await sdk.loadAgent('84532:1298'); const sameAgent = sdk.createA2AClient(agent); // returns the Agent as-is ``` ``` -------------------------------- ### Perform HTTP Requests with x402 Payment Handling Source: https://context7.com/agent0lab/agent0-ts/llms.txt The `request` and `fetchWithX402` methods handle HTTP requests, including automatic x402 (HTTP 402 Payment Required) responses. On success (2xx), they return the parsed result. On 402, they return an object indicating payment is required without throwing an exception. ```typescript import { isX402Required } from 'agent0-sdk'; // GET a payment-required API const result = await sdk.request<{ tweets: unknown[] }>({ url: 'https://twitter.x402.agentbox.fyi/search?q=AI&limit=5', method: 'GET', }); if (isX402Required(result)) { // Inspect options console.log('Payment required. Options:', result.x402Payment.accepts); // Pay with first EVM option const data = await result.x402Payment.pay(0); console.log(data.tweets); } else { console.log(result.tweets); } // POST with payment header pre-attached const postResult = await sdk.request({ url: 'https://api.example.com/generate', method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ prompt: 'Summarize this.' }), parseResponse: (res) => res.json() as Promise<{ text: string }>, }); if (!postResult.x402Required) { console.log(postResult.text); } // Pay using payFirst() (auto-selects chain with sufficient balance) if (isX402Required(result)) { const data = await result.x402Payment.payFirst?.(); console.log(data); } ``` -------------------------------- ### Give Feedback Source: https://github.com/agent0lab/agent0-ts/blob/main/README.md Submits feedback for an agent, optionally including off-chain data prepared with `prepareFeedbackFile`. ```APIDOC ## Give Feedback ### Description Submits feedback for an agent, including on-chain and optional off-chain data. ### Method `sdk.giveFeedback(agentId, value, tag1, tag2, endpoint, feedbackFile)` ### Parameters #### Path Parameters - **agentId** (string) - Required - The ID of the agent receiving feedback (e.g., 'chainId:agentId'). - **value** (number | string) - Required - The feedback value. - **tag1** (string) - Optional - First tag for the feedback. - **tag2** (string) - Optional - Second tag for the feedback. - **endpoint** (string) - Optional - On-chain endpoint for feedback submission. - **feedbackFile** (object) - Optional - The off-chain feedback file prepared using `prepareFeedbackFile`. ### Request Example ```typescript // Give feedback with optional off-chain file const tx = await sdk.giveFeedback( '11155111:123', 85, // value (number|string) 'data_analyst', // tag1 (optional) 'finance', // tag2 (optional) 'https://api.example.com/feedback', // endpoint (optional on-chain) feedbackFile // optional off-chain file ); // Wait for confirmation to get receipt and result const { receipt, result: feedback } = await tx.waitConfirmed(); ``` ```