From 8c49095c2fbcaa16b5c832ba4dccee4cf470053c Mon Sep 17 00:00:00 2001 From: Anand Chandrashekar Date: Mon, 1 Sep 2025 09:47:39 +0530 Subject: [PATCH] OpenAI and CrewAI examples --- deployed-agents/CrewAI/README.md | 28 +--- .../CrewAI/crewai-integration-example.py | 124 ++++++++---------- deployed-agents/OpenAI/README.md | 56 +------- .../OpenAI/openai-integration-example.py | 19 ++- 4 files changed, 66 insertions(+), 161 deletions(-) diff --git a/deployed-agents/CrewAI/README.md b/deployed-agents/CrewAI/README.md index 71847ef..79ca49a 100644 --- a/deployed-agents/CrewAI/README.md +++ b/deployed-agents/CrewAI/README.md @@ -1,38 +1,16 @@ # 🤖 Corvic MCP with CrewAI -This tutorial demonstrates how to use Corvic's MCP protocol with CrewAI to analyze video game sales data, perform content research, and write results to a markdown file. - ---- - -## 📘 Use Case - -Using a Corvic-powered agent, CrewAI identifies the top game genre by global sales, searches for relevant content using Serper, and writes the results to a file using CrewAI's file writer tool. +This tutorial demonstrates how to use Corvic's MCP HTTP Streamable protocol with CrewAI. --- ## ✅ Prerequisites -1. Deploy a Corvic agent using the parquet version of the [video game sales dataset](https://www.kaggle.com/datasets/gregorut/videogamesales). -2. Configure your Python environment with: +1. Configure your Python environment with: - `crewai` - `serper-dev-tool` - `corvic-mcp` -3. Obtain your Corvic MCP endpoint and token. - ---- - -## 🧠 Question Asked - -```text -Pass the following question to the tool as is (do not convert to SQL): Group all the data by Genre and find the top titles by global sales. Provide the top 1 genre in a tabular format. -``` - -## 📤 Response - -The output written to `results_with_content.md` includes a tabular summary of the top genre by sales and curated content recommendations (e.g., related to Action and Grand Theft Auto V). - -![Result Preview](../../assets/images/output_crewai_example.png) - +2. Obtain your Corvic MCP endpoint and token. Replace `YOUR-MCP-URL-HERE` with Corvic MCP endpoint and `YOUR-CORVIC-TOKEN-HERE` with token. --- Need help? Contact [support@corvic.ai](mailto:support@corvic.ai) or visit [https://www.corvic.ai](https://www.corvic.ai). \ No newline at end of file diff --git a/deployed-agents/CrewAI/crewai-integration-example.py b/deployed-agents/CrewAI/crewai-integration-example.py index d12007e..136d55e 100644 --- a/deployed-agents/CrewAI/crewai-integration-example.py +++ b/deployed-agents/CrewAI/crewai-integration-example.py @@ -1,75 +1,55 @@ -from crewai import Agent, Task, Crew, Process -from tools.serper import SerperDevTool -from tools.file_writer import FileWriterTool -from mcp_adapter import MCPServerAdapter - -token = "YOUR-CORVIC-API-TOKEN" - -serverparams = { - "url": "", # Replace with your deployed agent's endpoint - "headers": { - "Authorization": f"{token}" +#!/usr/bin/env python +import warnings + +from crewai import Agent, Crew, Process, Task +from crewai_tools import MCPServerAdapter + +warnings.filterwarnings("ignore", category=SyntaxWarning, module="pysbd") + + +def run(): + """ + Run the crew. + """ + token = 'YOUR-CORVIC-TOKEN-HERE' + server_params = { + "url": "YOUR-MCP-URL-HERE", + # Replace with your actual Streamable HTTP server URL + "headers": { + "Authorization": f"{token}" + }, + "timeout": 6000, + "transport": "streamable-http" } -} - -with MCPServerAdapter(serverparams) as tools: - print('configuring agent') - - analyst = Agent( - role='Customer service agent', - goal="Pass the following question to the tool as is (do not convert to SQL): Group all the data by Genre and find the top titles by global sales. Provide the top 1 genre in a tabular format.", - backstory='You are a customer service expert', - verbose=True, - allow_delegation=False, - tools=tools - ) - - content_tool = SerperDevTool() - content_researcher = Agent( - role="Content Researcher", - goal="Look for genre information in the data returned by the analyst and find relevant content for that genre. Return top 3 hits", - backstory="You are a content recommender", - tools=[content_tool], - verbose=True, - ) - - fw_tool = FileWriterTool() - writer = Agent( - role='Creative writer', - goal="Data from content_researcher should be written to a file named results_with_content.md in markdown format.", - backstory='You are a documentation expert', - verbose=True, - allow_delegation=False, - tools=[fw_tool] - ) - - print('configuring tasks') - corvic_task = Task( - description="Understand the question and provide response after using tools", - agent=analyst, - expected_output='Give a correct response' - ) - - content_recommender_task = Task( - description="Search and recommend content based on response from analyst", - agent=content_researcher, - expected_output="Interesting content" - ) - - writing_task = Task( - description="Write all the data from the content_researcher to a file", - agent=writer, - expected_output='Status of writing to file' - ) - print('configuring crew') - crew = Crew( - agents=[analyst, content_researcher, writer], - tasks=[corvic_task, content_recommender_task, writing_task], - process=Process.sequential, - verbose=True - ) + try: + with MCPServerAdapter(server_params) as tools: + print(f"Available tools (manual Streamable HTTP): {[tool.name for tool in tools]}") + + http_agent = Agent( + role="HTTP Service Integrator", + goal="Utilize tools from a remote MCP server via Streamable HTTP.", + backstory="An AI agent adept at interacting with complex web services.", + tools=tools, + verbose=True, + ) + + http_task = Task( + description="What is the mpg for valiant?", + expected_output="The result of the complex data query.", + agent=http_agent, + ) + + http_crew = Crew( + agents=[http_agent], + tasks=[http_task], + verbose=True, + process=Process.sequential + ) + """Creates the CrewWithCorvic crew""" + result = http_crew.kickoff() + print(result) + + except Exception as e: + raise Exception(f"An error occurred while running the crew: {e}") - print('running') - result = crew.kickoff() - print(result) diff --git a/deployed-agents/OpenAI/README.md b/deployed-agents/OpenAI/README.md index a907d60..a1d23a1 100644 --- a/deployed-agents/OpenAI/README.md +++ b/deployed-agents/OpenAI/README.md @@ -1,63 +1,11 @@ -# 🎮 Corvic AI + OpenAI Integration: Structured Data Example +# 🎮 Corvic AI + OpenAI Integration Example: MCP with Streamable HTTP Protocol -This example demonstrates how to integrate Corvic AI with an OpenAI agent framework to analyze structured data from a parquet file containing video game sales information. - ---- - -## 📘 Use Case - -In this tutorial, you'll upload a parquet file containing data about video game sales and ask Corvic to provide a report. - ---- - -## ✅ Prerequisites - -1. **Download the CSV Dataset**: Obtain the video game sales data from [Kaggle](https://www.kaggle.com/datasets/gregorut/videogamesales). - -2. **Convert CSV to Parquet**: Use Python to convert the CSV file to Parquet format: - - ```python - import pandas as pd - - df = pd.read_csv("vgsales.csv") - df.to_parquet("vgsales.parquet", index=False) - ``` - -3. **Upload to Corvic**: Follow the documentation [here](https://app.corvic.ai/docs/howToUseCorvic/pipelines#create-pipelines) to create an agent using this parquet file. - -4. **Deploy the Agent**: Deploy the agent and obtain the MCP endpoint and access token. - ---- - -## 🧠 Question Asked - -```text -Group all the data by name and find the top titles by global sales. -Output the name and the total global sales in a tabular format. -``` - -## 📤 Response - -The Corvic agent will process the parquet data and return a report including the top-performing video game titles. - -| Title | Total Global Sales | -| --------------------------- | ------------------ | -| Grand Theft Auto V | 64.29 | -| Call of Duty: Black Ops | 30.99 | -| Call of Duty: Modern Warfare 3 | 30.71 | -| Call of Duty: Black Ops II | 29.59 | -| Call of Duty: Ghosts | 28.80 | -| Call of Duty: Black Ops 3 | 26.72 | -| Call of Duty: Modern Warfare 2 | 25.02 | -| Minecraft | 24.01 | -| Grand Theft Auto IV | 22.53 | -| Call of Duty: Advanced Warfare| 21.78 | +This example demonstrates how to integrate Corvic AI with an OpenAI agent framework to analyze structured data using MCP and Streamable HTTP Protocol --- ## 📄 Notes -- Ensure that the `vgsales.parquet` file is correctly formatted and uploaded to the Corvic platform. - Replace `` and `` with your actual endpoint and token. - The agent is instructed to use tools exclusively for answering queries. diff --git a/deployed-agents/OpenAI/openai-integration-example.py b/deployed-agents/OpenAI/openai-integration-example.py index 02e72ba..5b6ed46 100644 --- a/deployed-agents/OpenAI/openai-integration-example.py +++ b/deployed-agents/OpenAI/openai-integration-example.py @@ -1,16 +1,17 @@ from agents import Agent, Runner -from agents.mcp import MCPServerSseParams, MCPServerSse +from agents.mcp import MCPServerStreamableHttp, MCPServerStreamableHttpParams async def run(): - params = MCPServerSseParams( - url="", # Replace with your deployed agent's endpoint + params = MCPServerStreamableHttpParams( + url="MCP_ENDPOINT", + # Replace with your deployed agent's endpoint headers={ - "Authorization": "" # Replace with your API token + "Authorization": "YOUR_CORVIC_API_TOKEN", + # Replace with your API token }, - timeout=500, - sse_read_timeout=500 + timeout=500 ) - corvic_mcp_server = MCPServerSse(name="corvic agent", params=params, client_session_timeout_seconds=500) + corvic_mcp_server = MCPServerStreamableHttp(name="corvic agent", params=params, client_session_timeout_seconds=500) print('connecting') await corvic_mcp_server.connect() tools = await corvic_mcp_server.list_tools() @@ -23,8 +24,6 @@ async def run(): mcp_servers=[corvic_mcp_server] ) # - result = await Runner.run(agent, "Group all the data by name and find the top titles by " - "global sales. Output the name and the total global sales in a " - "tabular format.") + result = await Runner.run(agent, "YOUR QUERY HERE") print(result.final_output) await corvic_mcp_server.cleanup()