Skip to content

nirav-gondaliya/upi-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

upi-agent

A minimal AI agent in TypeScript that connects to the upi-mcp MCP server and uses an LLM to call its tools — turning a plain-English request into a real UPI payment link or QR code.

Built from scratch (no agent framework) to show the core of how agents actually work: the agent loop + an MCP client. The AI decides which tools to use — you don't tell it.

What it does

You give it a request in plain English, e.g.:

"Make a UPI link to pay rahul@oksbi ₹1500"

…and the agent figures out the rest on its own — picking the right tool, calling it, and replying with the result.

How it works — the agent loop

1. Send the conversation + available tools to the LLM
2. LLM replies → tool request OR final answer
3. If a tool: run it via the MCP server, feed the result back
4. Repeat until the LLM gives a final answer

The tools live in a separate MCP server (upi-mcp); this agent is the MCP client that launches it, lists its tools, and runs them when the LLM asks.

Stack

  • TypeScript (strict)
  • @modelcontextprotocol/sdk — MCP client (connects to upi-mcp)
  • openai SDK pointed at Groq (free, OpenAI-compatible API)
  • dotenv — loads the API key

Requirements

  • Node.js 18+
  • A free Groq API key — get one at console.groq.com (no credit card)
  • The upi-mcp server — pulled from npm automatically, or built locally

Setup

git clone https://github.com/<your-username>/upi-agent.git
cd upi-agent
npm install

Create a .env file with your key:

GROQ_API_KEY=your_groq_key_here

⚠️ .env is gitignored — never commit your key.

Build:

npm run build

Run

node dist/index.js

Watch the agent decide which tool to call, run it via upi-mcp, and return the link/QR.

Configuration

  • The request: edit the messages array in src/index.ts.
  • The model: llama-3.3-70b-versatile (any Groq tool-capable model works).
  • Where the MCP server comes from — two options in the StdioClientTransport:
    • From npm (portable, works anywhere): command: "npx", args: ["-y", "upi-mcp"]
    • From a local build: command: "node", args: ["/path/to/upi-mcp/dist/index.js"]

Reliability note

Open-weight models occasionally malform a tool call (Groq returns tool_use_failed). This is LLM non-determinism, not a code bug. Mitigations used / recommended:

  • temperature: 0 for more deterministic output
  • a retry around the LLM call (production agents should retry, since no model is 100%)

Not yet (roadmap)

  • Interactive mode — currently runs one hardcoded request
  • Retry wrapper baked in

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors