PageSourceSearch

https://innovationlab.fetch.ai/resources/assets/js/0aced4ca.0a40d0a2.js

js fetch.ai collected 2026-09-24 09:38:37 UTC 29,995 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkinnovation_labs=self.webpackChunkinnovation_labs||[]).push([[890],{75016:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>l,contentTitle:()=>o,default:()=>h,frontMatter:()=>i,metadata:()=>s,toc:()=>c});const s=JSON.parse('{"id":"examples/other-frameworks/langchain","title":"Langchain Agent","description":"This document is a comprehensive guide to help users integrate LangChain tools into Fetch.ai\'s ecosystem using the provided Alphavantage Agent and User Agent scripts. These agents work together to fetch stock prices and demonstrate how LangChain tools can interact seamlessly with Agentverse agents.","source":"@site/versioned_docs/version-1.0.5/examples/other-frameworks/langchain.mdx","sourceDirName":"examples/other-frameworks","slug":"/examples/other-frameworks/langchain","permalink":"/resources/docs/examples/other-frameworks/langchain","draft":false,"unlisted":false,"tags":[],"version":"1.0.5","frontMatter":{"id":"langchain","title":"Langchain Agent"}}');var r=t(74848),a=t(28453);const i={id:"langchain",title:"Langchain Agent"},o="Getting a langchain tool on Agentverse Marketplace",l={},c=[{value:"Overview",id:"overview",level:2},{value:"Purpose",id:"purpose",level:3},{value:"Key Features",id:"key-features",level:3},{value:"Architecture Diagram",id:"architecture-diagram",level:3},{value:"Prerequisites",id:"prerequisites",level:2},{value:"Environment Setup",id:"environment-setup",level:3},{value:"Required Libraries",id:"required-libraries",level:3},{value:"Environment Variables",id:"environment-variables",level:3},{value:"Alphvantage Agent Script",id:"alphvantage-agent-script",level:2},{value:"Script Breakdown (stockprice.py)",id:"script-breakdown-stockpricepy",level:3},{value:"User Agent Script",id:"user-agent-script",level:2},{value:"Script Breakdown (user.py)",id:"script-breakdown-userpy",level:3},{value:"Steps to run Scripts",id:"steps-to-run-scripts",level:2},{value:"Run the Alphavantage Agent script",id:"run-the-alphavantage-agent-script",level:4},{value:"Output",id:"output",level:4},{value:"Run the User Agent script",id:"run-the-user-agent-script",level:4},{value:"Output",id:"output-1",level:4},{value:"Interacting with the Agents",id:"interacting-with-the-agents",level:3},{value:"Debugging Common Issues",id:"debugging-common-issues",level:2}];function d(e){const n={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",header:"header",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.header,{children:(0,r.jsx)(n.h1,{id:"getting-a-langchain-tool-on-agentverse-marketplace",children:"Getting a langchain tool on Agentverse Marketplace"})}),"\n",(0,r.jsxs)(n.p,{children:["This document is a comprehensive guide to help users integrate ",(0,r.jsx)(n.strong,{children:"LangChain"})," tools into ",(0,r.jsx)(n.strong,{children:"Fetch.ai's"})," ecosystem using the provided ",(0,r.jsx)(n.strong,{children:"Alphavantage Agent"})," and ",(0,r.jsx)(n.strong,{children:"User Agent scripts"}),". These agents work together to fetch stock prices and demonstrate how LangChain tools can interact seamlessly with Agentverse agents."]}),"\n",(0,r.jsx)(n.h2,{id:"overview",children:"Overview"}),"\n",(0,r.jsx)(n.h3,{id:"purpose",children:"Purpose"}),"\n",(0,r.jsx)(n.p,{children:"The purpose of this script is to:"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Use LangChain integration"})," to fetch stock prices from the Alpha Vantage API."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Demonstrate communication"})," between agents within the Fetch.ai Agentverse."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Provide"})," a clear example of webhook-based communication."]}),"\n"]}),"\n",(0,r.jsx)(n.h3,{id:"key-features",children:"Key Features"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsx)(n.li,{children:"The__ Alphavantage Agent__ handles requests for stock prices using the Alpha Vantage API."}),"\n",(0,r.jsxs)(n.li,{children:["The ",(0,r.jsx)(n.strong,{children:"User Agent"})," acts as a client to forward requests and retrieve responses."]}),"\n",(0,r.jsxs)(n.li,{children:["Communication is done via ",(0,r.jsx)(n.strong,{children:"HTTP webhooks"})," registered with Fetch.ai\u2019s Agentverse."]}),"\n"]}),"\n",(0,r.jsx)(n.h3,{id:"architecture-diagram",children:"Architecture Diagram"}),"\n",(0,r.jsx)("div",{style:{textAlign:"center"},children:(0,r.jsx)("img",{src:"/resources/img/langchain-tool.png",alt:"tech-architecture",style:{width:"75%",maxWidth:"600px"}})}),"\n",(0,r.jsx)(n.h2,{id:"prerequisites",children:"Prerequisites"}),"\n",(0,r.jsx)(n.h3,{id:"environment-setup",children:"Environment Setup"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Python 3.8"})," or higher."]}
1),"\n",(0,r.jsxs)(n.li,{children:["A ",(0,r.jsx)(n.strong,{children:"virtual environment"})," (recommended)."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Flask"})," and related libraries installed."]}),"\n"]}),"\n",(0,r.jsx)(n.h3,{id:"required-libraries",children:"Required Libraries"}),"\n",(0,r.jsx)(n.p,{children:"Install the necessary libraries using:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{children:"pip install flask flask-cors fetchai langchain \u201cflask[async]\u201d\n"})}),"\n",(0,r.jsx)(n.admonition,{type:"note",children:(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.strong,{children:"Note:"})," For more advanced dependency management, consider creating a ",(0,r.jsx)(n.code,{children:"requirements.txt"})," and using ",(0,r.jsx)(n.code,{children:"pip install -r requirements.txt"}),"."]})}),"\n",(0,r.jsx)(n.h3,{id:"environment-variables",children:"Environment Variables"}),"\n",(0,r.jsxs)(n.p,{children:["Create a ",(0,r.jsx)(n.code,{children:".env"})," file in the project directory with the following content:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{children:"AV_STOCKPRICE_AI_KEY=<your_alpha_vantage_ai_key>\nAGENTVERSE_API_KEY=<your_agentverse_api_key>\nUSER_STOCKPRICE_AI_KEY=<your_user_stockprice_ai_key>\nALPHAVANTAGE_API_KEY=<your_agentverse_api_key>\n"})}),"\n",(0,r.jsxs)(n.p,{children:["Replace the placeholders with your respective API keys.\nSign up for a free API key at ",(0,r.jsx)(n.a,{href:"https://www.alphavantage.co/",children:"Alpha Vantage"}),"."]}),"\n",(0,r.jsx)(n.h2,{id:"alphvantage-agent-script",children:"Alphvantage Agent Script"}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.strong,{children:"Alphavantage Agent"})," Script focuses on:"]}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Registering"})," with Fetch.ai\u2019s Agentverse."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Handling requests"})," to fetch stock prices."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Responding"})," to the User Agent with stock price data."]}),"\n"]}),"\n",(0,r.jsx)(n.h3,{id:"script-breakdown-stockpricepy",children:"Script Breakdown (stockprice.py)"}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Required Libraries"})}),"\n",(0,r.jsx)(n.p,{children:"The script imports the required modules for:"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Identity Management"}),": Fetch.ai\u2019s Identity and registration modules."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Communication"}),": Flask for HTTP handling and Fetch.ai\u2019s communication utilities."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Alpha Vantage API"}),": LangChain\u2019s ",(0,r.jsx)(n.code,{children:"AlphaVantageAPIWrapper"}),"."]}),"\n"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:"import os\nimport logging\nimport asyncio\nfrom uagents_core.crypto import Identity\nfrom flask import Flask, request, jsonify\nfrom fetchai.registration import register_with_agentverse\nfrom fetchai.communication import parse_message_from_agent, send_message_to_agent\nfrom langchain_community.utilities.alpha_vantage import AlphaVantageAPIWrapper\n"})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Setting Up Logging"})}),"\n",(0,r.jsx)(n.p,{children:"Logging is configured to monitor the agent\u2019s activities:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:"logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')\nlogger = logging.getLogger(__name__)\n"})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Flask Webhook"})}),"\n",(0,r.jsx)(n.p,{children:"The Flask app is created to handle incoming webhook requests:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:"flask_app = Flask(__name__)\n"})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Alpha Vantage Integration"})}),"\n",(0,r.jsx)(n.p,{children:"An instance of the Alpha Vantage wrapper is created:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:"alpha_vantage = AlphaVantageAPIWrapper()\n"})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Fetch Stock Price Function"})}),"\n",(0,r.jsx)(n.p,{children:"The get_stock_price function fetches stock prices asynchronously from the Alpha Vantage API:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:"async def get_stock_price(symbol):\n    response = alpha_vantage._get_quote_endpoint(symbol)\n    return response['Global Quote']['05. price']\n"})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Webhook Endpoint"})}),"\n",(0,r.jsx)(n.p,{children:"The /webhook route handles requests sent by other agents:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:'@flask_app.route(\'/webhook\', methods=[\'POST\'])\nasync def webhook():\n    global response\n    global av_identity\n    try:\n        # Parse incoming message\n        data = request.get_data().decode(\'utf-8\')\n        message = parse_message_from_agent(data)\n        symbol = message.payload.get("request", "")\n        agent_address = message.sender\n\n        if not symbol:\n            return jsonify({"status": "error", "message": "No data path provided"}), 400\n\n        price = await get_stock_price(symbol)\n        print(price)\n        payload = {\'price\': price}\n        send_message_to_agent(av_identity, agent_address, payload)\n        return jsonify({"status": "
1wiki_content_sent"})\n\n    except Exception as e:\n        logger.error(f"Error in webhook: {e}")\n        return jsonify({"status": "error", "message": str(e)}), 500\n'})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Registering the Agent"})}),"\n",(0,r.jsx)(n.p,{children:"The init_agent function registers the Alphavantage Agent with Fetch.ai\u2019s Agentverse:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:'def init_agent():\n   global av_identity\n   try:\n       av_identity = Identity.from_seed(os.getenv("AV_STOCKPRICE_AI_KEY"), 0)\n       register_with_agentverse(\n           identity=av_identity,\n           url="http://localhost:5008/webhook",\n           agentverse_token=os.getenv("AGENTVERSE_API_KEY"),\n           agent_title="Alphavantage Stock Price Langchain tool",\n           # Define the client agent\'s metadata\n           readme = """\n               <description>This is langchain based alphavantage tool to get the latest stock price for the given symbol.</description>\n               <use_cases>\n                   <use_case>Gives you the stock price of given symbol.</use_case>\n               </use_cases>\n               <payload_requirements>\n               <description>Expects the symbol for which you want stock price for.</description>\n                   <payload>\n                       <requirement>\n                           <parameter>symbol</parameter>\n                           <description>Symbol for which you want to check the stock price?</description>\n                       </requirement>\n                   </payload>\n               </payload_requirements>\n           """\n       )\n       logger.info("Langchain Alphavantage tool agent registered successfully!")\n   except Exception as e:\n       logger.error(f"Error initializing agent: {e}")\n       raise\n'})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Running the Agent"})}),"\n",(0,r.jsx)(n.p,{children:"The Flask server runs on port 5008 to handle requests:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:'if __name__ == "__main__":\n    init_agent()\n    flask_app.run(host="0.0.0.0", port=5008, debug=True)\n'})}),"\n",(0,r.jsx)(n.h2,{id:"user-agent-script",children:"User Agent Script"}),"\n",(0,r.jsx)(n.p,{children:"The User Agent script acts as the client that forwards requests to the Alphavantage Agent and retrieves responses."}),"\n",(0,r.jsx)(n.h3,{id:"script-breakdown-userpy",children:"Script Breakdown (user.py)"}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Importing Libraries"})}),"\n",(0,r.jsx)(n.p,{children:"The script imports required libraries for Flask, Fetch.ai, and communication:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:"from flask_cors import CORS\nfrom uagents_core.crypto import Identity\nfrom fetchai import fetch\nfrom fetchai.registration import register_with_agentverse\nfrom fetchai.communication import parse_message_from_agent, send_message_to_agent\nimport logging\nimport os\nfrom dotenv import load_dotenv\nfrom flask import Flask, jsonify, request\n"})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Setting Up Logging and Flask"})}),"\n",(0,r.jsx)(n.p,{children:"Logging and Flask are configured similarly to the Alphavantage Agent:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:"logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')\nlogger = logging.getLogger(__name__)\napp = Flask(__name__)\nCORS(app)\n"})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Initializing the User Agent"})}),"\n",(0,r.jsx)(n.p,{children:"The init_client function initializes and registers the User Agent with Agentverse:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:'def init_client():\n   """Initialize and register the client agent."""\n   global client_identity\n   try:\n       # Load the client identity from environment variables\n       client_identity = Identity.from_seed(os.getenv("USER_STOCKPRICE_AI_KEY"), 0)\n       logger.info(f"Client agent started with address: {client_identity.address}")\n\n       # Define the client agent\'s metadata\n       readme = """\n       <description>Frontend client that tests with Stocks price using alphavantage.</description>
1\n       <use_cases>\n           <use_case>Sends Request to the AI Agent to check stock price</use_case>\n       </use_cases>\n       <payload_requirements>\n           <description>Expects request which is to be sent to another agent.</description>\n           <payload>\n               <requirement>\n                   <parameter>request</parameter>\n                   <description>This is the request which is to be sent to other agent</description>\n               </requirement>\n           </payload>\n       </payload_requirements>\n       """\n\n       # Register the agent with Agentverse\n       register_with_agentverse(\n           identity=client_identity,\n           url="http://localhost:5002/api/webhook",\n           agentverse_token=os.getenv("AGENTVERSE_API_KEY"),\n           agent_title="User agent for Stock Price check",\n           readme=readme\n       )\n\n       logger.info("Client agent registration complete!")\n\n   except Exception as e:\n       logger.error(f"Initialization error: {e}")\n       raise\n'})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Searching Agents"})}),"\n",(0,r.jsx)(n.p,{children:"The /api/search-agents endpoint allows users to search for available agents:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:"# searching the agents which can create dashboard on agentverse\[email protected]('/api/search-agents', methods=['GET'])\ndef search_agents():\n   \"\"\"Search for available dashboard agents based on user input.\"\"\"\n   try:\n       # Extract user input from query parameters\n       user_query = request.args.get('query', '')\n       if not user_query:\n           return jsonify({\"error\": \"Query parameter 'query' is required.\"}), 400\n\n       # Fetch available agents based on user query\n       available_ais = fetch.ai(user_query)  # Pass the user query to the fetch.ai function\n       print(f'---------------------{available_ais}----------------------')\n\n       # Access the 'ais' list within 'agents' (assuming fetch.ai returns the correct structure)\n       agents = available_ais.get('ais', [])\n       print(f'----------------------------------{agents}------------------------------------')\n\n       extracted_data = []\n       for agent in agents:\n           name = agent.get('name')  # Extract agent name\n           address = agent.get('address')\n\n           # Append formatted data to extracted_data list\n           extracted_data.append({\n               'name': name,\n               'address': address,\n           })\n\n       # Format the response with indentation for readability\n       response = jsonify(extracted_data)\n       response.headers.add('Content-Type', 'application/json; charset=utf-8')\n       response.headers.add('Access-Control-Allow-Origin', '*')\n       response.headers.add('Access-Control-Allow-Headers', 'Content-Type')\n       return response, 200\n\n   except Exception as e:\n       logger.error(f\"Error finding agents: {e}\")\n       return jsonify({\"error\": str(e)}), 500\n"})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Sending Data to Alphavantage Agent"})}),"\n",(0,r.jsx)(n.p,{children:"The /api/send-data endpoint forwards stock price requests to the Alphavantage Agent:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:'@app.route(\'/api/send-data\', methods=[\'POST\'])\ndef send_data():\n   """Send payload to the selected agent based on provided address."""\n   global agent_response\n   agent_response = None\n\n   try:\n       # Parse the request payload\n       data = request.json\n       payload = data.get(\'payload\')  # Extract the payload dictionary\n       agent_address = data.get(\'agentAddress\')  # Extract the agent address\n\n       # Validate the input data\n       if not payload or not agent_address:\n           return jsonify({"error": "Missing payload or agent address"}), 400\n\n       logger.info(f"Sending payload to agent: {agent_address}")\n       logger.info(f"Payload: {payload}")\n\n       # Send the payload to the specified agent\n       send_message_to_agent(\n           client_identity,  # Frontend client identity\n           agent_address,    # Agent address where we have to send the data\n           payload           # Payload containing the data\n       )\n\n       return jsonify({"status": "request_sent", "agent_address": agent_address, "payload": payload})\n\n   except Exception as e:\n       logger.error(f"Error sending data to agent: {e}")\n       return jsonify({"error": str(e)}), 500\n'})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Webhook Endpoint"})}),"\n",(0,r.jsx)(n.p,{children:"The /webhook route handles requests sent by other agents:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:'# app route to get recieve the messages on the agent\[email protected](\'/api/webhook\', methods=[\'POST\'])\ndef webhook():\n    """Handle incoming messages from the dashboard agent."""\n    global agent_response\n    try:\n        # Parse the incoming webhook message\n        data = request.get_data().decode("utf-8")\n        logger.info("Received response")\n\n        message = parse_message_from_agent(data)\n        agent_response = message.payload\n\n        logger.info(f"Processed response: {agent_response}")\n        return jsonify({"status": "success"})\n\n    except Exception as e:\n        logger.error(f"Error in webhook: {e}")\n        return jsonify({"error": str(e)}), 500\n'})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Retrieving the Agent's Response"})}),"\n",(0,r.jsx)(n.p,{children:"The /api/get-response endpoint retrieves the response 
1(stock price) from the stocks price Agent and saves it :"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:'@app.route(\'/api/get-response\', methods=[\'GET\'])\ndef get_response():\n    global agent_response\n    try:\n        if agent_response:\n            response = agent_response\n            print(f\'stock_price : {response}\')\n            agent_response = None  # Clear the response after sending\n            \n            keys = list(response.keys())  # Convert dict_keys to a list\n            first_key = keys[0]           # Get the first key\n            response_final = response.get(first_key, "") \n            logger.info(f"Got response for the stock price {response_final}")\n            return jsonify({"stock_price": response_final})\n        else:\n            return jsonify({"error": "No storm response available"}), 404\n\n    except Exception as e:\n        logger.error(f"Error creating markdown file: {e}")\n        return jsonify({"error": str(e)}), 500\n'})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Running the agent"})}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:'# function to start the flask server\ndef start_server():\n    """Start the Flask server."""\n    try:\n        # Load environment variables\n        load_dotenv()\n        init_client()\n        app.run(host="0.0.0.0", port=5002)\n    except Exception as e:\n        logger.error(f"Server error: {e}")\n        raise\n\nif __name__ == "__main__":\n    start_server()\n'})}),"\n",(0,r.jsx)(n.h2,{id:"steps-to-run-scripts",children:"Steps to run Scripts"}),"\n",(0,r.jsx)(n.p,{children:"Follow these steps to get both the Alphavantage Agent and User Agent scripts up and running."}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"1. Start the Alphavantage Agent"})}),"\n",(0,r.jsxs)(n.p,{children:["Ensure the ",(0,r.jsx)(n.code,{children:"AV_STOCKPRICE_AI_KEY"})," and ",(0,r.jsx)(n.code,{children:"AGENTVERSE_API_KEY"})," values are correctly set in the ",(0,r.jsx)(n.code,{children:".env"})," file."]}),"\n",(0,r.jsx)(n.h4,{id:"run-the-alphavantage-agent-script",children:"Run the Alphavantage Agent script"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"python3 av_agent.py\n"})}),"\n",(0,r.jsx)(n.h4,{id:"output",children:"Output"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"(my_env) abhi@Fetchs-MacBook-Pro Langchain Tool Example % python3 av_agent.py\nINFO:fetchai:Registering with Almanac API\nINFO:fetchai:Completed registering agent with Agentverse\nINFO:__main__:Langchain Alphavantage tool agent registered successfully!\n * Serving Flask app 'av_agent'\n * Debug mode: on\nINFO:werkzeug:WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.\n * Running on all addresses (0.0.0.0)\n * Running on http://127.0.0.1:5008\nINFO:werkzeug:Press CTRL+C to quit\nINFO:werkzeug: * Restarting with stat\nINFO:fetchai:Registering with Almanac API\nINFO:fetchai:Completed registering agent with Agentverse\nINFO:__main__:Langchain Alphavantage tool agent registered successfully!\n"})}),"\n",(0,r.jsxs)(n.p,{children:["The agent listens on ",(0,r.jsx)(n.strong,{children:"port 5008"})," for requests."]}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"2. Start the User Agent"})}),"\n",(0,r.jsxs)(n.p,{children:["Ensure the ",(0,r.jsx)(n.code,{children:"USER_STOCKPRICE_AI_KEY"})," and ",(0,r.jsx)(n.code,{children:"AGENTVERSE_API_KEY"})," values are correctly set in the ",(0,r.jsx)(n.code,{children:".env"})," file."]}),"\n",(0,r.jsx)(n.h4,{id:"run-the-user-agent-script",children:"Run the User Agent script"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"python3 user_agent.py\n"})}),"\n",(0,r.jsx)(n.h4,{id:"output-1",children:"Output"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"(my_env) abhi@Fetchs-MacBook-Pro Langchain Tool Example % python3 user_agent.py\nINFO:__main__:Client agent started with address: agent1qtyqvwlqgd96jzdcd9yj9nem09j48xel2envjdcnvxpx2nfq0rygwxfg3kv\nINFO:fetchai:Registering with Almanac API\nINFO:fetchai:Completed registering agent with Agentverse\nINFO:__main__:Client agent registration complete!\n * Serving Flask app 'user_agent'\n * Debug mode: off\nINFO:werkzeug:WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.\n * Running on all addresses (0.0.0.0)\n * Running on http://127.0.0.1:5002\n * Running on http://192.168.0.106:5002\n"})}),"\n",(0,r.jsx)(n.h3,{id:"interacting-with-the-agents",children:"Interacting with the Agents"}),"\n",(0,r.jsx)(n.p,{children:"Once both agents are running, use the following endpoints from another terminal:"}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"1. Search for Agents"})}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:'curl -X GET "http://localhost:5002/api/search-agents?query=I%20want%20to%20check%20the%20stock%20price"\n'})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Sample Output"})}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:'[{"address":"agent1qwkzy0twyd27egqfrcw8m6vdtsz7hrm9leu7jfezzzlgckywj7shytz5kf6","name":"Alphavantage Stock Price Langchain tool"}
1,\n{"address":"agent1qtzp03dh92dldvsmr7v0xxvwcfwnpctftjqwdrqrmfszex0dal7pzapsy8d","name":"User agent for Stock Price check"},\n{"address":"agent1qtnc7ruc63g3n84qczekqc6qwp0e5ayvs3v8e5pae563qrqcf852xlqz2pk","name":"Alphavantage Stock Price Langchain tool"},\n{"address":"agent1qtyqvwlqgd96jzdcd9yj9nem09j48xel2envjdcnvxpx2nfq0rygwxfg3kv","name":"User agent for Stock Price check"},\n{"address":"agent1q05k0g4f90zka3m34zj52sdyqtvvvzyry0lc0sdzcdm2tjllkqeruqhue4z","name":"IL Testing user"},\n{"address":"agent1qtmkpt8lhyx4u2ndzcgr7jkjuuade4ay78yld2ngaghs03z6qve3senwrsa","name":"Penny"},\n{"address":"agent1qtxx79e689zwjlh7m8dsfuv7lyn45d2xapr4p9w2u9axvzm487tzjfwqzdp","name":"Penny"},\n{"address":"agent1qvc0em6vrlr80txaz3ksy7tspzaxl564jwqtaana7exehg0hz7gl6zg0wl0","name":"Penny"},\n{"address":"agent1qw5s6e7mxcd8mp6f2vvunk9rklwnv8ynft43unx77syea4nnskxyj4yk5xq","name":"Penny"},\n{"address":"agent1qwlyun6slk2gy8uxnnmvy35tuw2ftp44wza6yfgw06ca9axlllzaxgj5jut","name":"Penny"}]\n'})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"2. Send a Stock Price Request"})}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:'curl -X POST "http://localhost:5002/api/send-data" \\\n-H "Content-Type: application/json" \\\n-d \'{\n    "payload": {"request": "AAPL"},\n    "agentAddress": "agent1qwkzy0twyd27egqfrcw8m6vdtsz7hrm9leu7jfezzzlgckywj7shytz5kf6"\n}\'\n'})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Sample Output"})}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:'{"agent_address":"agent1qwkzy0twyd27egqfrcw8m6vdtsz7hrm9leu7jfezzzlgckywj7shytz5kf6","payload":{"request":"AAPL"},"status":"request_sent"}\n'})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"3. Retrieve the Stock Price Response"})}),"\n",(0,r.jsx)(n.p,{children:"Fetch the stock price response from the User Agent:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:'curl -X GET "http://localhost:5002/api/get-response"\n'})}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"Sample Output"})}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:'{"stock_price":"234.4000"}\n'})}),"\n",(0,r.jsx)(n.h2,{id:"debugging-common-issues",children:"Debugging Common Issues"}),"\n",(0,r.jsx)(n.p,{children:"Agent Registration Fails:"}),"\n",(0,r.jsx)(n.p,{children:"a. Check the .env file for correct API keys."}),"\n",(0,r.jsx)(n.p,{children:"b. Ensure the AGENTVERSE_API_KEY is valid."}),"\n",(0,r.jsx)(n.p,{children:"404 Errors:"}),"\n",(0,r.jsx)(n.p,{children:"a. Verify that both agents are running on their respective ports (5008 and 5002 in this case)."}),"\n",(0,r.jsx)(n.p,{children:"b. Double-check the agentAddress in requests."}),"\n",(0,r.jsxs)(n.p,{children:["You now have an ",(0,r.jsx)(n.strong,{children:"Alphavantage Agent"})," integrated with the ",(0,r.jsx)(n.strong,{children:"Fetch.ai Agentverse"})," for fetching stock prices via ",(0,r.jsx)(n.strong,{children:"LangChain"}),". Feel free to adapt the example to include other APIs, advanced AI features, or additional endpoints."]})]})}function h(e={}){const{wrapper:n}={...(0,a.R)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(d,{...e})}):d(e)}},28453:(e,n,t)=>{t.d(n,{R:()=>i,x:()=>o});var s=t(96540);const r={},a=s.createContext(r);function i(e){const n=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),s.createElement(a.Provider,{value:n},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.