Skip to content

Agent + MCP v2 (WIP, don't merge yet)#1409

Draft
maxkosty wants to merge 14 commits intomasterfrom
agent-mcp-v2
Draft

Agent + MCP v2 (WIP, don't merge yet)#1409
maxkosty wants to merge 14 commits intomasterfrom
agent-mcp-v2

Conversation

@maxkosty
Copy link
Copy Markdown
Collaborator

@maxkosty maxkosty commented Apr 6, 2026

Goal

This builds on the initial agent+mcp work which had a lot of hardcoded filler data by actually plugging into Empower DB with products and reviews (recommend the gadgets, i.e. actual products being sold instead of recommending plants). Most importantly it integrates with our backend APIs including /checkout highlighting how errors and slowdowns happen downstream from the agent - a unique differentiator that pure AI observability platforms don't have.

TODO:

  • merge this into this branch

@maxkosty maxkosty requested a review from sdzhong April 6, 2026 20:09
@maxkosty maxkosty requested review from a team and ndmanvar as code owners April 6, 2026 20:09
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
empower Ignored Ignored Preview Apr 6, 2026 8:45pm

Request Review

Comment on lines +49 to +53
CHECKOUT (when user says they want to check out):
Use the MCP 'checkout' tool with:
- email: "demo@empower-plant.com"
- name: "Demo Customer"
- address: "123 Plant Street, Garden City, CA 94000"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The agent's instructions for the checkout tool don't match the tool's required input schema, causing checkout to fail due to validation errors.
Severity: CRITICAL

Suggested Fix

Update the agent's instructions in shopping_agent.py to request all necessary fields for the checkout tool. Implement logic to track the user's cart state (items, quantities, total) within the SessionState. Ensure the agent can construct the full cart and form objects required by the checkout tool's Zod schema before making the tool call.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: agent/app/agents/shopping_agent.py#L49-L53

Potential issue: The agent's instructions for the `checkout` tool are incomplete. The
instructions tell the LLM to call the tool with only `email`, `name`, and `address`.
However, the tool's schema requires a full `cart` object (containing items, quantities,
and total) and a `form` object with separate fields for `firstName`, `lastName`, `city`,
`state`, etc. The application lacks the necessary state management to track cart
contents and construct this required data structure. As a result, the MCP SDK's
validation will reject the tool call, causing the checkout process to fail for the user.

Did we get this right? 👍 / 👎 to inform future reviews.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 6, 2026

⚠️ JUnit XML file not found

The CLI was unable to find any JUnit XML files to upload.
For more help, visit our troubleshooting guide.

@maxkosty maxkosty marked this pull request as draft April 6, 2026 20:48
Comment on lines +58 to +62
CHECKOUT_RESULT:{"success":false,"error":"Error message"}

ERROR HANDLING: If checkout or any operation fails, display the error and stop. Do NOT offer to retry or troubleshoot.

STYLE: Concise, friendly, ONE question at a time.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The parse_agent_output function processes CHECKOUT_RESULT line-by-line and fails to parse multi-line JSON from the LLM, causing the result to be displayed as plain text.
Severity: MEDIUM

Suggested Fix

Modify the parse_agent_output function to handle multi-line JSON. When a CHECKOUT_RESULT: marker is found, buffer subsequent lines until a complete JSON object is formed (e.g., by tracking curly brace counts or using a timeout) before attempting to parse it with json.loads().

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: agent/app/agents/shopping_agent.py#L58-L62

Potential issue: The `parse_agent_output` function in `shopping_agent.py` processes
agent output line-by-line. For `CHECKOUT_RESULT` messages, it expects the entire JSON
payload to be on a single line. However, LLMs may format JSON across multiple lines for
readability. When this happens, the parser attempts to call `json.loads()` on an
incomplete fragment (e.g., just `{`), which throws a `JSONDecodeError`. The error
handling then appends the line to a message buffer as plain text. As a result, the
structured `checkout_result` card is not rendered in the UI, and the user sees the raw,
unformatted JSON text instead, degrading the user experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants