How myttyyytytyyttt/polyagent works
Project Type and Purpose
• PolyAgent is a Python-based agent framework and CLI tool for autonomous trading on Polymarket.
• It combines AI prompt engineering, Retrieval-Augmented Generation (RAG), real-time data connectors, and blockchain interactions.
File Structure
• Top-level modules:
• agents/ ← Core application logic and AI agent workflows
– application/ ← Agent orchestration: creator, executor, cron jobs, trade runner, prompts
– connectors/ ← Standardized interfaces to external data sources & APIs
– polymarket/ ← Polymarket-specific API clients (Gamma, Polymarket DEX)
– utils/ ← Shared utilities and Pydantic models
• scripts/ ← CLI entrypoint, server, Docker orchestration
• Dockerfile, .github/, CI workflows, tests/
Extract Architecture Insights from README
• Modular “connectors” layer abstracts Chroma vector DB, news, web search, and Polymarket APIs.
• “application” layer composes AI agents to fetch data, build prompts, analyze markets, and execute trades.
• Scripts provide end-user CLI and Dockerized deployment.
• External dependencies: OpenAI LLM, NewsAPI, Search API, Polymarket Gamma API, Polygon wallet/blockchain.
A. User Interface & Orchestration
1. CLI / scripts/python/cli.py
2. Docker/ bash scripts for build & dev
B. Agent Application Layer (agents/application)
1. Creator – instantiates agent workflows
2. Cron – scheduling & periodic triggers
3. Executor – runs AI pipelines & RAG loops
4. Trade – finalizes and sends orders
5. Prompts – prompt templates & engineering
C. Connectors Layer (agents/connectors & agents/polymarket)
1. ChromaConnector – vector DB storage & retrieval
2. NewsConnector – NewsAPI feed ingestion
3. SearchConnector – real-time web search
4. GammaMarketClient – Polymarket metadata & markets
5. PolymarketClient – order creation, signing, execution
D. Data Models & Utilities (agents/utils)
– Pydantic models for Market, Event, Trade, etc.
– Common helper functions
1. OpenAI LLM endpoint
2. NewsAPI
3. Search engine API
4. Polymarket Gamma API
5. Polygon Blockchain / Wallet
F. Data Stores
– Local vector store (Chroma DB)
– Environment variables (.env)
Relationships & Data Flow
• User invokes CLI/server → triggers Agent Creator/Executor.
• Executor calls Connectors to fetch:
• Market metadata (GammaMarketClient)
• Historical data & news (NewsConnector)
• Web search results (SearchConnector)
• RAG vector queries (ChromaConnector)
• Data models unify fetched data (agents/utils/objects.py).
• Executor & Prompts compose LLM requests → OpenAI API.
• Analysis output → Trade module builds order → PolymarketClient signs & sends to Blockchain.
• Cron scheduler can re-invoke workflows per ANALYSIS_DELAY_SECONDS.
• Docker container encapsulates the entire runtime with environment variables.
Architectural Patterns & Principles
• Layered modular design: UI → Application → Connectors → External.
• Dependency inversion: connectors implement standard interfaces.
• Pydantic for data validation & typing.
• Separation of concerns: trading logic decoupled from data retrieval.
• Configurable via environment variables and Docker.