An intelligent, self-improving research system powered by Cloudflare Workers and OpenAI. This system uses two Durable Objects to recursively generate, verify, and refine AI research responses.
- Iterative Research: Uses multiple AI passes to refine responses
- Fact Checking: Verifies information through a dedicated fact-checking phase
- Edge Computing: Built on Cloudflare Workers for global performance
- Durable Objects: Maintains consistency across research iterations
- Node.js or Bun (latest version)
- Cloudflare Workers account
- OpenAI API key
-
Clone and install dependencies:
git clone https://github.com/acoyfellow/ai-research-agent.git cd ai-research-agent npm install # or bun install
-
Copy
wrangler.toml.example
towrangler.toml
and configure:name = "ai-research-Agent" main = "src/index.ts" compatibility_date = "2024-02-01" [vars] OPENAI_API_KEY = "your-key-here" OPENAI_MODEL = "gpt-4o-mini" MAX_ITERATIONS = "5" CONFIDENCE_THRESHOLD = "0.9"
-
Deploy:
npm run deploy # or bun run deploy
Send a POST request to start research:
curl -X POST https://<your-worker>.workers.dev/start \
-H "Content-Type: application/json" \
-d '{"topic": "Explain quantum computing in simple terms"}'
{
"research": "Quantum computing explained in simple terms...",
"iteration": 2
}
- Initial Research: ResearchFetcherDO generates the first research pass using OpenAI
- Fact Checking: FactCheckerDO verifies and improves the research
- Iteration: Process repeats until max iterations or confidence threshold is met
- Response: Returns the final refined research
Variable | Description | Default |
---|---|---|
OPENAI_API_KEY |
Your OpenAI API key | Required |
OPENAI_MODEL |
OpenAI model to use | gpt-4o-mini |
MAX_ITERATIONS |
Maximum research passes | 5 |
CONFIDENCE_THRESHOLD |
Required accuracy threshold | 0.9 |
-
Start local development:
npm run dev # or bun run dev
-
Visit
http://localhost:8787
to use the web interface
MIT License - see LICENSE for details
- Star this repo
- Report issues
- Submit PRs
- Share with others
Built with ❤️ using Cloudflare Workers and OpenAI
Inspired by sunil pai @threepointone