pending tmo work

This commit is contained in:
Adil Hafeez 2025-09-07 23:26:00 -07:00
parent bb71d041a0
commit 22c84fb689
No known key found for this signature in database
GPG key ID: 9B18EF7691369645
17 changed files with 1626 additions and 94 deletions

View file

View file

@ -0,0 +1,38 @@
version: v0.1.0
agents:
- name: rag_assistant
description: t-mobile virtual assistant for device contracts.
instructions: |
You are a virtual assistant, here to help users answer questions from device contracts team.
Use following instructions to process the user request,
1. Use query_processor_agent to understand user queries
2. Use search_documents to fetch relevant information
3. Use response_generator_agent to formulate clear responses
model: openai/gpt-4o
tools:
- name: query_processor_agent
# Parses user queries and extracts metadata, also handles clarification workflow
protocol: mcp
endpoint: https://localhost:10500
- name: search_documents
# Searches the document store for relevant information
protocol: mcp
endpoint: https://localhost:10501
- name: response_generator_agent
# Generates a final response based on user query and retrieved context
protocol: mcp
endpoint: https://localhost:10502
listener:
port: 8000
protocol: openai
path: /v1/chat/completions
llm_providers_v2:
default:
listener:
port: 12000
protocol: openai
providers:
- access_key: ${OPENAI_API_KEY}
model: openai/gpt-4o

View file

@ -0,0 +1,4 @@
# Netscape HTTP Cookie File
# https://curl.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.

View file

@ -0,0 +1,19 @@
[project]
name = "rag_agent"
version = "0.1.0"
description = "RAG Agent"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
"click>=8.2.1",
"mcp>=1.13.1",
"fastmcp>=2.12.2",
"pydantic>=2.11.7",
]
[project.scripts]
rag_agent = "rag_agent:main"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

View file

@ -0,0 +1,30 @@
import click
from mcp.server.fastmcp import FastMCP
mcp = None
@click.command()
@click.option('--transport', 'transport', default='stdio')
@click.option('--host', 'host', default='localhost')
@click.option('--port', 'port', default=10101)
@click.option('--agent', 'agent', default=None)
def main(host, port, agent, transport):
print(f"Starting agent(s): {agent if agent else 'all'}")
global mcp
mcp = FastMCP("RAG Agent Demo", host=host, port=port)
if agent == "query_parser":
import rag_agent.query_parser
elif agent == "document_store":
import rag_agent.document_store
elif agent == "response_generator":
import rag_agent.response_generator
else:
import rag_agent.query_parser
import rag_agent.document_store
import rag_agent.response_generator
print("All agents loaded.")
mcp.run(transport=transport)
if __name__ == '__main__':
main()

View file

@ -0,0 +1,16 @@
from pydantic import BaseModel
from . import mcp
class QueryRequest(BaseModel):
query: str
metadata: dict | None = None
class QueryResponse(BaseModel):
query: str
results: list
@mcp.tool()
def query_rag_store(request: QueryRequest):
"""Query the RAG document store."""
return {"query": request.query, "results": []}

View file

@ -0,0 +1,13 @@
from pydantic import BaseModel
from . import mcp
class Response(BaseModel):
query: str
metadata: dict
@mcp.tool()
def parse_query(query):
"""Parse the user query and returns metadata extracted from query."""
return Response(query=query, metadata={
"is_valid": True
})

View file

@ -0,0 +1,6 @@
from . import mcp
@mcp.tool()
def generate_response(query, context):
"""Generate a response based on the user query and context."""
return {"query": query, "context": context, "response": "This is a generated response."}

View file

@ -0,0 +1,35 @@
# Step 1: Initialize session
POST http://localhost:10101/mcp
Content-Type: application/json
Accept: application/json, text/event-stream
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
}
}
}
HTTP 200
[Captures]
session_id: header "mcp-session-id"
# # Step 2: List tools (use session ID from previous response)
POST http://localhost:10101/mcp
Content-Type: application/json
Accept: application/json, text/event-stream
mcp-session-id: 07603206a9b44a3d91d76f6b16f24faa
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list",
"params": {}
}

View file

@ -0,0 +1,31 @@
### Step 1: Initialize session
POST http://localhost:10101/mcp
Content-Type: application/json
Accept: application/json, text/event-stream
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
}
}
}
### Step 2: List tools (use session ID from previous response)
POST http://localhost:10101/mcp
Content-Type: application/json
Accept: application/json, text/event-stream
mcp-session-id: af2e2dace64c48f99ac3536faeaa3c68
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list",
"params": {}
}

1224
demos/use_cases/rag_agent/uv.lock generated Normal file

File diff suppressed because it is too large Load diff