Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 7 additions & 23 deletions deployed-agents/python/README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
# 🐍 Corvic AI Python Integration Example
# 🐍 Corvic AI Python Integration Example using MCP (HTTP Streamable)

This example demonstrates how to use the Corvic AI MCP protocol in Python to query a deployed agent that processes PDF-based enterprise data.
This example demonstrates how to use the Corvic AI MCP (HTTP) protocol in Python to query a deployed agent that processes PDF-based enterprise data.

---

## 📘 Use Case

We will ask a question that requires the Corvic agent to look up and reason through a NAICS (North American Industry Classification System) PDF document.

---

## ✅ Prerequisites

1. Complete the setup steps in this [blog post](https://corvic.substack.com/p/automating-address-updates-with-corvic?open=false#%C2%A7the-corvic-solution-automation-without-overhead).
2. Upload the [NAICS 2022 Manual PDF](https://www.census.gov/naics/reference_files_tools/2022_NAICS_Manual.pdf) and deploy your agent on Corvic’s platform.
3. Once deployed, copy the MCP endpoint and access token.

---

## 🧰 Integration Steps

1. Use the `mcp` Python package to create an `sse_client` connection to the deployed agent.
1. Use the `mcp` Python package to create an `streamablehttp_client` connection to the deployed agent.
2. Pass the MCP endpoint and your API token in the request headers.
3. Initialize the session and retrieve the list of available tools (Corvic currently supports a single tool: `query`).
4. Call the `query` tool with your question via the `query_content` argument.
Expand All @@ -31,23 +18,20 @@ We will ask a question that requires the Corvic agent to look up and reason thro
## 🧠 Question Asked

```text
Map the NAICS code 441228 from 2017 to the 2022 NAICS code.
What is the MPG for Valiant?
```

## 📤 Response

The response will look as below. The mapping as well as the relevant section of the document is retrieved by the Corvic agent.

![NAICS Mapping Result](../../assets/images/python_readme_naics_output.png)
The response will look as below.

The MPG for Valiant is 18
---

## 📄 Notes

- The `query_content` argument is **required**.
- Replace the placeholder token with your actual Corvic API token.
- You can save or manipulate the response as needed (e.g., convert to HTML, display in UI, etc).

- Replace the placeholder token with your actual Corvic API token and Agent URI.
---

Need help? Contact [support@corvic.ai](mailto:support@corvic.ai) or visit [https://www.corvic.ai](https://www.corvic.ai).
33 changes: 16 additions & 17 deletions deployed-agents/python/python-integration-example.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
import asyncio
from mcp import ClientSession
from mcp.client.sse import sse_client
from mcp.client.streamable_http import streamablehttp_client


async def run():
async with sse_client(
"<YOUR_CORVIC_AI_MCP_ENDPOINT>", # Replace with your deployed agent's endpoint
headers={
"Authorization": "<YOUR_CORVIC_API_TOKEN>" # Replace with your API token
},
) as (read, write):
url = "<YOUR_CORVIC_AI_MCP_ENDPOINT>"
headers = {
"Content-Type": "application/json",
"Accept": "application/json, text/event-stream",
"Authorization": "<YOUR_CORVIC_API_TOKEN>"
}
async with streamablehttp_client(url=url, headers=headers) as (read, write, session_id):
async with ClientSession(read, write) as session:
# Initialize the connection
await session.initialize()

# List available tools
tools = await session.list_tools()
print(tools)

# Call a tool
result = await session.call_tool(
"query", arguments={"query_content": "Map the NAICS code 441228 from 2017 to the 2022 NAICS code."}
"query", arguments={"query_content": "What is the MPG for Valiant?"}
)
# Save results to Markdown
with open("naics_query.md", "a") as file:
for content in result.content:
file.write(content.text)
all_content = ''
for content in result.content:
all_content += content.text
print(content.text)
return all_content


if __name__ == "__main__":
asyncio.run(run())