How hyperf/odin works
Project type and purpose
• Odin is a PHP‑based framework/library for building LLM‑powered applications.
• It unifies multiple model providers (OpenAI, Azure, AWS Bedrock, etc.), supports tool/function calling, memory management, vector retrieval (via Qdrant), and an agent framework.
File structure
• Top‑level directories:
• src: core code organized into subpackages (Api, Agent, Memory, Model, Tool, Prompt, VectorStore, etc.)
• doc/user-guide: detailed user documentation
• examples: usage examples for AWS, OpenAI, streams, tools, exceptions
• tests: unit and integration suites
• Key configuration: composer.json, .php-cs-fixer.php, phpunit.xml
• Deployment: GitHub Actions workflows under .github/workflows
README insights
• Describes supported features (multi‑model, unified interface, function calls, memory, vector search, agents, streaming)
• Lists system requirements and quickstart (composer install, config publish, .env, etc.)
Main components and interactions
a. API Layer
• ClientFactory → ConfigProvider → AbstractClient/Provider implementations (OpenAI, AzureOpenAI, AWSBedrock)
• Request/RequestOptions → Transport (HTTP/SSEClient) → Response/ResponseHandler
b. Model Layer
• ModelFactory → AbstractModel/Provider‑specific Model classes
• ModelOptions drives parameterization
c. Prompt Layer
• PromptInterface + concrete templates (.prompt files) generate the raw text or JSON function calls
d. Memory Layer
• MemoryManager → multiple Policies (time window, token limit, summarization, relevancy) → Driver (InMemoryDriver, custom drivers)
• MessageHistory organizes system/user/assistant/tool messages
e. Tool/Agent Layer
• ToolDefinition/Schema → AbstractTool implementations → Agent coordinating ToolUseAgent and MultiToolUseParallelTool
f. VectorStore Layer
• QdrantFactory → Qdrant client/config → semantic search for knowledge retrieval
g. Exception/Logging
• Centralized exception hierarchy for API, configuration, model, network errors
• Logger for diagnostic and stream‑level error detection
Relationships and data flow
• Application code invokes Odin’s public façade (Factory, ConfigProvider)
• Factories spin up ApiClient + Model + Prompt
• Prompt + conversation memory → Request → Transport → External LLM service
• Response → converters → Response objects → consumed by application or agent
• Agents may call Tools (with definitions) → ToolExecutor → external APIs or business logic → back into conversation
• For retrieval tasks: Agent or developer code calls VectorStore → Qdrant → returns documents → fed back into prompt
Architectural patterns and design principles
• Dependency Injection (ConfigProvider, Factories)
• Strategy/Provider pattern for multi‑model support
• Builder pattern for request/response conversion
• Policy pattern for memory management
• Modular layering (API, Model, Prompt, Memory, Agent/Tool, VectorStore)
Detail level
• And group all src/* subpackages into logical layers
• External dependencies clearly (LLM providers, Qdrant)
• Agent/Tool workflow as a distinct flow