{"slug": "how-i-built-a-self-verifying-ai-agent-with-dynamodb-and-react-reasoning", "title": "How I Built a Self-Verifying AI Agent with DynamoDB and ReAct Reasoning", "summary": "A developer built ChemSpectra Agent, an FTIR spectral analysis system that uses a ReAct loop with Qwen-3.7-Max function calling to autonomously select from five analytical tools and self-verify its conclusions. The system detects evidence conflicts between tools, estimates confidence, and automatically triggers verification rounds when confidence is below 0.75 or conflicts exist, with all sessions persisted to DynamoDB for audit trails.", "body_md": "*Built for the #H0Hackathon — Hack the Zero Stack with Vercel v0 and AWS Databases*\n\nMost AI pipelines follow a fixed script: input in, output out, nobody checks the work. For the H0 hackathon (Track 2: Monetizable B2B App), I built **ChemSpectra Agent** — an FTIR spectral analysis system where the AI verifies its own conclusions and self-corrects when evidence conflicts.\n\nInstead of hardcoding which tools to call, the agent uses a ReAct loop with Qwen-3.7-Max function calling. The LLM autonomously selects from 5 tools — `identify_material`\n\n(130K+ reference spectra), `explain_peaks`\n\n, `assign_functional_groups`\n\n, `match_library_topk`\n\n, and `search_public_results`\n\n. A material ID request might trigger two tools; a deformulation request triggers all three analytical tools. The LLM decides, not the developer.\n\nAfter tools return results, `_detect_evidence_conflicts()`\n\ncompares outputs. If `identify_material`\n\nsays \"PET\" but `assign_functional_groups`\n\nfound no ester groups, that's a contradiction:\n\n```\nexpected_groups = {\n    \"pet\": [\"ester\", \"c=o\", \"aromatic\"],\n    \"nylon\": [\"amide\", \"n-h\", \"c=o\"],\n}\n```\n\nThe agent estimates confidence from match scores, candidate score gaps, and functional group coverage. Below 0.75 confidence or any conflicts, a verification round fires automatically:\n\n```\nneeds_verification = (\n    confidence < 0.75 or len(conflicts) > 0\n)\n```\n\nThe agent gets told exactly what went wrong and calls additional tools to investigate. Post-verification confidence is logged, creating traces like `[0.62, 0.84]`\n\n.\n\nEvery session persists to DynamoDB with 30-day TTL — tool call logs, confidence traces, synthesis, final report. But we went deeper than basic CRUD:\n\n`gsi-created`\n\n(partition: `ALL`\n\n, sort: `created_at`\n\n) replaces full-table scan with efficient time-ordered query; `gsi-material`\n\n(partition: `top_match`\n\n, sort: `created_at`\n\n) enables \"show me all PET analyses\" aggregation`chemspectra-stats`\n\ntable tracks `total_analyses`\n\nand `total_tools_called`\n\nvia DynamoDB `ADD`\n\noperations, safe under concurrent requests`attribute_not_exists(session_id) OR step <> :confirmed`\n\nto prevent concurrent overwrites of finalized reportsRegulated industries (pharma, forensics) require this audit trail. DynamoDB fits because the primary access is single-item by `session_id`\n\n, the GSIs cover the two secondary patterns, and TTL handles cleanup automatically.\n\nThe loop runs 2-4 iterations in under 30 seconds. Self-repair for malformed LLM JSON has near-100% recovery. This turns \"AI that gives answers\" into \"AI that checks its work\" — essential when reports go into regulatory filings.\n\n**Try it**: [chemspectra-agent-h0.vercel.app](https://chemspectra-agent-h0.vercel.app) | **Code**: [github.com/jxbaoxiaodong/chemspectra-agent-h0](https://github.com/jxbaoxiaodong/chemspectra-agent-h0)\n\n*This article was written as part of my participation in the H0 AWS+Vercel Hackathon.*", "url": "https://wpnews.pro/news/how-i-built-a-self-verifying-ai-agent-with-dynamodb-and-react-reasoning", "canonical_source": "https://dev.to/bob_lee_2d29b22cee96eb65f/how-i-built-a-self-verifying-ai-agent-with-dynamodb-and-react-reasoning-6dp", "published_at": "2026-06-26 04:34:25+00:00", "updated_at": "2026-06-26 05:03:51.392239+00:00", "lang": "en", "topics": ["artificial-intelligence", "ai-agents", "large-language-models", "ai-tools", "developer-tools"], "entities": ["ChemSpectra Agent", "Qwen-3.7-Max", "DynamoDB", "Vercel", "AWS", "H0 Hackathon", "ReAct"], "alternates": {"html": "https://wpnews.pro/news/how-i-built-a-self-verifying-ai-agent-with-dynamodb-and-react-reasoning", "markdown": "https://wpnews.pro/news/how-i-built-a-self-verifying-ai-agent-with-dynamodb-and-react-reasoning.md", "text": "https://wpnews.pro/news/how-i-built-a-self-verifying-ai-agent-with-dynamodb-and-react-reasoning.txt", "jsonld": "https://wpnews.pro/news/how-i-built-a-self-verifying-ai-agent-with-dynamodb-and-react-reasoning.jsonld"}}