agent-framework-lib 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. agent_framework_lib-0.5.0/ARCHITECTURE.md +582 -0
  2. agent_framework_lib-0.5.0/LICENSE +21 -0
  3. agent_framework_lib-0.5.0/MANIFEST.in +78 -0
  4. agent_framework_lib-0.5.0/PKG-INFO +1261 -0
  5. agent_framework_lib-0.5.0/README.md +1148 -0
  6. agent_framework_lib-0.5.0/agent_framework/__init__.py +365 -0
  7. agent_framework_lib-0.5.0/agent_framework/chart_generation/llm_refinement_loop.py +425 -0
  8. agent_framework_lib-0.5.0/agent_framework/core/__init__.py +5 -0
  9. agent_framework_lib-0.5.0/agent_framework/core/agent_interface.py +460 -0
  10. agent_framework_lib-0.5.0/agent_framework/core/agent_provider.py +473 -0
  11. agent_framework_lib-0.5.0/agent_framework/core/base_agent.py +1072 -0
  12. agent_framework_lib-0.5.0/agent_framework/core/elasticsearch_config_provider.py +534 -0
  13. agent_framework_lib-0.5.0/agent_framework/core/model_clients.py +544 -0
  14. agent_framework_lib-0.5.0/agent_framework/core/model_config.py +854 -0
  15. agent_framework_lib-0.5.0/agent_framework/core/model_router.py +752 -0
  16. agent_framework_lib-0.5.0/agent_framework/core/rich_content_prompt_unsused_to_be_deleted.py +448 -0
  17. agent_framework_lib-0.5.0/agent_framework/core/state_manager.py +378 -0
  18. agent_framework_lib-0.5.0/agent_framework/implementations/__init__.py +11 -0
  19. agent_framework_lib-0.5.0/agent_framework/implementations/llamaindex_agent.py +822 -0
  20. agent_framework_lib-0.5.0/agent_framework/implementations/llamaindex_memory_adapter.py +334 -0
  21. agent_framework_lib-0.5.0/agent_framework/implementations/microsoft_agent.py +415 -0
  22. agent_framework_lib-0.5.0/agent_framework/memory/__init__.py +125 -0
  23. agent_framework_lib-0.5.0/agent_framework/memory/agent_mixin.py +344 -0
  24. agent_framework_lib-0.5.0/agent_framework/memory/base.py +325 -0
  25. agent_framework_lib-0.5.0/agent_framework/memory/config.py +405 -0
  26. agent_framework_lib-0.5.0/agent_framework/memory/manager.py +705 -0
  27. agent_framework_lib-0.5.0/agent_framework/memory/providers/__init__.py +34 -0
  28. agent_framework_lib-0.5.0/agent_framework/memory/providers/graphiti_provider.py +716 -0
  29. agent_framework_lib-0.5.0/agent_framework/memory/providers/memori_provider.py +552 -0
  30. agent_framework_lib-0.5.0/agent_framework/memory/tools.py +307 -0
  31. agent_framework_lib-0.5.0/agent_framework/monitoring/__init__.py +11 -0
  32. agent_framework_lib-0.5.0/agent_framework/monitoring/elasticsearch_circuit_breaker.py +359 -0
  33. agent_framework_lib-0.5.0/agent_framework/monitoring/elasticsearch_logging.py +473 -0
  34. agent_framework_lib-0.5.0/agent_framework/monitoring/error_handling.py +612 -0
  35. agent_framework_lib-0.5.0/agent_framework/monitoring/error_logging.py +516 -0
  36. agent_framework_lib-0.5.0/agent_framework/monitoring/performance_monitor.py +616 -0
  37. agent_framework_lib-0.5.0/agent_framework/monitoring/progress_tracker.py +443 -0
  38. agent_framework_lib-0.5.0/agent_framework/monitoring/resource_manager.py +438 -0
  39. agent_framework_lib-0.5.0/agent_framework/processing/__init__.py +7 -0
  40. agent_framework_lib-0.5.0/agent_framework/processing/ai_content_management.py +940 -0
  41. agent_framework_lib-0.5.0/agent_framework/processing/markdown_converter.py +978 -0
  42. agent_framework_lib-0.5.0/agent_framework/processing/multimodal_integration.py +391 -0
  43. agent_framework_lib-0.5.0/agent_framework/py.typed +2 -0
  44. agent_framework_lib-0.5.0/agent_framework/session/__init__.py +1 -0
  45. agent_framework_lib-0.5.0/agent_framework/session/elasticsearch_session_storage.py +1442 -0
  46. agent_framework_lib-0.5.0/agent_framework/session/session_storage.py +2399 -0
  47. agent_framework_lib-0.5.0/agent_framework/skills/__init__.py +169 -0
  48. agent_framework_lib-0.5.0/agent_framework/skills/agent_mixin.py +333 -0
  49. agent_framework_lib-0.5.0/agent_framework/skills/base.py +371 -0
  50. agent_framework_lib-0.5.0/agent_framework/skills/builtin/__init__.py +136 -0
  51. agent_framework_lib-0.5.0/agent_framework/skills/builtin/chart_skill.py +248 -0
  52. agent_framework_lib-0.5.0/agent_framework/skills/builtin/file_access_skill.py +177 -0
  53. agent_framework_lib-0.5.0/agent_framework/skills/builtin/file_skill.py +148 -0
  54. agent_framework_lib-0.5.0/agent_framework/skills/builtin/form_skill.py +198 -0
  55. agent_framework_lib-0.5.0/agent_framework/skills/builtin/image_display_skill.py +175 -0
  56. agent_framework_lib-0.5.0/agent_framework/skills/builtin/mermaid_skill.py +245 -0
  57. agent_framework_lib-0.5.0/agent_framework/skills/builtin/multimodal_skill.py +162 -0
  58. agent_framework_lib-0.5.0/agent_framework/skills/builtin/optionsblock_skill.py +293 -0
  59. agent_framework_lib-0.5.0/agent_framework/skills/builtin/pdf_skill.py +209 -0
  60. agent_framework_lib-0.5.0/agent_framework/skills/builtin/pdf_with_images_skill.py +198 -0
  61. agent_framework_lib-0.5.0/agent_framework/skills/builtin/table_skill.py +184 -0
  62. agent_framework_lib-0.5.0/agent_framework/skills/builtin/web_search_skill.py +111 -0
  63. agent_framework_lib-0.5.0/agent_framework/skills/discovery_prompt.py +86 -0
  64. agent_framework_lib-0.5.0/agent_framework/skills/tools.py +192 -0
  65. agent_framework_lib-0.5.0/agent_framework/storage/__init__.py +41 -0
  66. agent_framework_lib-0.5.0/agent_framework/storage/file_storages.py +4627 -0
  67. agent_framework_lib-0.5.0/agent_framework/storage/file_system_management.py +2375 -0
  68. agent_framework_lib-0.5.0/agent_framework/storage/storage_optimizer.py +531 -0
  69. agent_framework_lib-0.5.0/agent_framework/tools/__init__.py +167 -0
  70. agent_framework_lib-0.5.0/agent_framework/tools/adaptive_pdf_css.py +574 -0
  71. agent_framework_lib-0.5.0/agent_framework/tools/base.py +171 -0
  72. agent_framework_lib-0.5.0/agent_framework/tools/chart_tools.py +394 -0
  73. agent_framework_lib-0.5.0/agent_framework/tools/file_access_tools.py +168 -0
  74. agent_framework_lib-0.5.0/agent_framework/tools/file_tools.py +226 -0
  75. agent_framework_lib-0.5.0/agent_framework/tools/html_content_analyzer.py +313 -0
  76. agent_framework_lib-0.5.0/agent_framework/tools/mermaid_tools.py +333 -0
  77. agent_framework_lib-0.5.0/agent_framework/tools/multimodal_tools.py +604 -0
  78. agent_framework_lib-0.5.0/agent_framework/tools/pdf_image_scaler.py +375 -0
  79. agent_framework_lib-0.5.0/agent_framework/tools/pdf_tools.py +612 -0
  80. agent_framework_lib-0.5.0/agent_framework/tools/pdf_with_images_tool.py +463 -0
  81. agent_framework_lib-0.5.0/agent_framework/tools/sizing_config.py +402 -0
  82. agent_framework_lib-0.5.0/agent_framework/tools/tabledata_tools.py +479 -0
  83. agent_framework_lib-0.5.0/agent_framework/tools/web_search_tools.py +185 -0
  84. agent_framework_lib-0.5.0/agent_framework/utils/__init__.py +27 -0
  85. agent_framework_lib-0.5.0/agent_framework/utils/path_utils.py +256 -0
  86. agent_framework_lib-0.5.0/agent_framework/utils/post_install.py +689 -0
  87. agent_framework_lib-0.5.0/agent_framework/utils/session_title_generator.py +468 -0
  88. agent_framework_lib-0.5.0/agent_framework/utils/special_blocks.py +249 -0
  89. agent_framework_lib-0.5.0/agent_framework/web/__init__.py +5 -0
  90. agent_framework_lib-0.5.0/agent_framework/web/admin_auth.py +251 -0
  91. agent_framework_lib-0.5.0/agent_framework/web/admin_models.py +108 -0
  92. agent_framework_lib-0.5.0/agent_framework/web/admin_router.py +327 -0
  93. agent_framework_lib-0.5.0/agent_framework/web/admin_services.py +640 -0
  94. agent_framework_lib-0.5.0/agent_framework/web/docs/CREATING_AGENTS.md +1561 -0
  95. agent_framework_lib-0.5.0/agent_framework/web/docs/DOCKER_SETUP.md +299 -0
  96. agent_framework_lib-0.5.0/agent_framework/web/docs/Dockerfile +49 -0
  97. agent_framework_lib-0.5.0/agent_framework/web/docs/MEMORY_INSTALLATION.md +808 -0
  98. agent_framework_lib-0.5.0/agent_framework/web/docs/README.md +1148 -0
  99. agent_framework_lib-0.5.0/agent_framework/web/docs/TOOLS_AND_MCP_GUIDE.md +2281 -0
  100. agent_framework_lib-0.5.0/agent_framework/web/docs/api-reference.md +1515 -0
  101. agent_framework_lib-0.5.0/agent_framework/web/docs/configuration.md +1036 -0
  102. agent_framework_lib-0.5.0/agent_framework/web/docs/docker-compose.yml +106 -0
  103. agent_framework_lib-0.5.0/agent_framework/web/docs/examples/agent_example_multi_skills.py +219 -0
  104. agent_framework_lib-0.5.0/agent_framework/web/docs/examples/agent_with_file_storage.py +178 -0
  105. agent_framework_lib-0.5.0/agent_framework/web/docs/examples/agent_with_mcp.py +207 -0
  106. agent_framework_lib-0.5.0/agent_framework/web/docs/examples/agent_with_memory.py +342 -0
  107. agent_framework_lib-0.5.0/agent_framework/web/docs/examples/agent_with_memory_graphiti.py +97 -0
  108. agent_framework_lib-0.5.0/agent_framework/web/docs/examples/agent_with_memory_hybrid.py +139 -0
  109. agent_framework_lib-0.5.0/agent_framework/web/docs/examples/agent_with_memory_simple.py +88 -0
  110. agent_framework_lib-0.5.0/agent_framework/web/docs/examples/custom_framework_agent.py +1271 -0
  111. agent_framework_lib-0.5.0/agent_framework/web/docs/examples/simple_agent.py +145 -0
  112. agent_framework_lib-0.5.0/agent_framework/web/docs/installation-guide.md +578 -0
  113. agent_framework_lib-0.5.0/agent_framework/web/documentation_generator.py +688 -0
  114. agent_framework_lib-0.5.0/agent_framework/web/helper_agent.py +1459 -0
  115. agent_framework_lib-0.5.0/agent_framework/web/helper_ui.html +948 -0
  116. agent_framework_lib-0.5.0/agent_framework/web/modern_ui.html +9694 -0
  117. agent_framework_lib-0.5.0/agent_framework/web/server.py +3996 -0
  118. agent_framework_lib-0.5.0/agent_framework/web/test_app.html +5480 -0
  119. agent_framework_lib-0.5.0/agent_framework_lib.egg-info/PKG-INFO +1261 -0
  120. agent_framework_lib-0.5.0/agent_framework_lib.egg-info/SOURCES.txt +152 -0
  121. agent_framework_lib-0.5.0/agent_framework_lib.egg-info/dependency_links.txt +1 -0
  122. agent_framework_lib-0.5.0/agent_framework_lib.egg-info/entry_points.txt +2 -0
  123. agent_framework_lib-0.5.0/agent_framework_lib.egg-info/requires.txt +92 -0
  124. agent_framework_lib-0.5.0/agent_framework_lib.egg-info/top_level.txt +1 -0
  125. agent_framework_lib-0.5.0/docs/CREATING_AGENTS.md +1561 -0
  126. agent_framework_lib-0.5.0/docs/DOCKER_SETUP.md +299 -0
  127. agent_framework_lib-0.5.0/docs/ELASTICSEARCH_DATA_STRUCTURES.md +1048 -0
  128. agent_framework_lib-0.5.0/docs/FILE_DOWNLOAD_LINKS.md +92 -0
  129. agent_framework_lib-0.5.0/docs/FILE_STORAGE_GUIDE.md +792 -0
  130. agent_framework_lib-0.5.0/docs/GETTING_STARTED.md +528 -0
  131. agent_framework_lib-0.5.0/docs/MEMORY_INSTALLATION.md +808 -0
  132. agent_framework_lib-0.5.0/docs/MULTIMODAL_TOOLS_GUIDE.md +432 -0
  133. agent_framework_lib-0.5.0/docs/PYPI_PUBLISHING.md +326 -0
  134. agent_framework_lib-0.5.0/docs/TOOLS_AND_MCP_GUIDE.md +2281 -0
  135. agent_framework_lib-0.5.0/docs/api-reference.md +1515 -0
  136. agent_framework_lib-0.5.0/docs/configuration.md +1036 -0
  137. agent_framework_lib-0.5.0/docs/installation-guide.md +578 -0
  138. agent_framework_lib-0.5.0/examples/README.md +453 -0
  139. agent_framework_lib-0.5.0/examples/agent_example_multi_skills.py +219 -0
  140. agent_framework_lib-0.5.0/examples/agent_with_custom_tools_file_storage.py +190 -0
  141. agent_framework_lib-0.5.0/examples/agent_with_file_storage.py +178 -0
  142. agent_framework_lib-0.5.0/examples/agent_with_mcp.py +207 -0
  143. agent_framework_lib-0.5.0/examples/agent_with_memory_graphiti.py +97 -0
  144. agent_framework_lib-0.5.0/examples/agent_with_memory_hybrid.py +139 -0
  145. agent_framework_lib-0.5.0/examples/agent_with_memory_simple.py +88 -0
  146. agent_framework_lib-0.5.0/examples/biagenttest.py +441 -0
  147. agent_framework_lib-0.5.0/examples/custom_framework_agent.py +1271 -0
  148. agent_framework_lib-0.5.0/examples/dependencies/docker-compose.yaml +26 -0
  149. agent_framework_lib-0.5.0/examples/pyproject.toml +158 -0
  150. agent_framework_lib-0.5.0/examples/simple_agent.py +145 -0
  151. agent_framework_lib-0.5.0/examples/skills_demo_agent.py +439 -0
  152. agent_framework_lib-0.5.0/pyproject.toml +441 -0
  153. agent_framework_lib-0.5.0/setup.cfg +4 -0
  154. agent_framework_lib-0.5.0/setup.py +43 -0
@@ -0,0 +1,582 @@
1
+ # Agent Framework Architecture
2
+
3
+ ## 1. Overview
4
+
5
+ This document outlines the architecture of the Agent Framework, designed to provide a robust, scalable, and extensible platform for serving conversational agents across multiple AI frameworks.
6
+
7
+ The primary architectural goal is **Framework-Agnostic Design with Separation of Concerns**. The framework completely decouples the web server layer from the implementation details of any specific agent framework (e.g., LlamaIndex, Microsoft Agent Framework). The server doesn't know how an agent manages its internal memory or state; its only job is to handle web requests and interact with a generic `AgentInterface`.
8
+
9
+ This design allows for easy extension to support other agent frameworks in the future without modifying the core server logic.
10
+
11
+ ### Key Architectural Improvements
12
+
13
+ **🎯 Framework-Agnostic Core**: The framework now provides a clean separation between framework-agnostic concerns (session management, state persistence, streaming, web server) and framework-specific implementations (LlamaIndex, Microsoft).
14
+
15
+ **🔄 Modular Architecture**: Clear folder structure organizing code by responsibility (core, session, storage, processing, tools, monitoring, web, implementations).
16
+
17
+ **🔌 Extensible Design**: Adding new agent frameworks requires only implementing the `AgentInterface` without touching core code.
18
+
19
+ ## 2. Folder Structure
20
+
21
+ The architecture is organized into logical modules, each with a single, well-defined responsibility:
22
+
23
+ ```
24
+ agent_framework/
25
+ ├── core/ # Framework-agnostic core components
26
+ │ ├── __init__.py
27
+ │ ├── agent_interface.py # Abstract agent interface
28
+ │ ├── base_agent.py # Generic base agent
29
+ │ ├── agent_provider.py # Agent lifecycle management (AgentManager)
30
+ │ ├── state_manager.py # State management & compression
31
+ │ ├── model_config.py # Multi-provider configuration
32
+ │ └── model_clients.py # LLM client factory
33
+
34
+ ├── session/ # Session management
35
+ │ ├── __init__.py
36
+ │ └── session_storage.py # Session persistence (Memory, MongoDB)
37
+
38
+ ├── storage/ # File storage
39
+ │ ├── __init__.py
40
+ │ ├── file_storages.py # Storage backends (Local, S3, MinIO)
41
+ │ ├── file_system_management.py # FileStorageManager
42
+ │ └── storage_optimizer.py # Storage optimization
43
+
44
+ ├── processing/ # Content processing
45
+ │ ├── __init__.py
46
+ │ ├── markdown_converter.py # File to markdown conversion
47
+ │ ├── multimodal_integration.py # Multimodal processing
48
+ │ └── ai_content_management.py # AI content management
49
+
50
+ ├── tools/ # Reusable tools
51
+ │ ├── __init__.py
52
+ │ └── multimodal_tools.py # Multimodal processing tools
53
+
54
+ ├── monitoring/ # Performance & monitoring
55
+ │ ├── __init__.py
56
+ │ ├── performance_monitor.py # Performance monitoring
57
+ │ ├── progress_tracker.py # Progress tracking
58
+ │ ├── resource_manager.py # Resource management
59
+ │ ├── error_handling.py # Error handling
60
+ │ └── error_logging.py # Logging configuration
61
+
62
+ ├── web/ # Web server & UI
63
+ │ ├── __init__.py
64
+ │ ├── server.py # FastAPI server
65
+ │ ├── modern_ui.html # Modern UI
66
+ │ └── test_app.html # Test application
67
+
68
+ ├── implementations/ # Framework-specific agents
69
+ │ ├── __init__.py
70
+ │ ├── llamaindex_agent.py # LlamaIndex implementation
71
+ │ └── microsoft_agent.py # Microsoft Agent Framework
72
+
73
+ ├── utils/ # Utilities
74
+ │ ├── __init__.py
75
+ │ └── special_blocks.py # Special block parsing
76
+
77
+ └── chart_generation/ # Chart generation
78
+ └── llm_refinement_loop.py # LLM refinement for charts
79
+ ```
80
+
81
+ ### Module Responsibilities
82
+
83
+ | Module | Responsibility |
84
+ |--------|---------------|
85
+ | **core/** | Framework-agnostic components: interfaces, base classes, state management, model configuration |
86
+ | **session/** | Session lifecycle and persistence (memory, MongoDB) |
87
+ | **storage/** | File storage backends and management (Local, S3, MinIO) |
88
+ | **processing/** | Content processing: markdown conversion, multimodal integration, AI content |
89
+ | **tools/** | Reusable tools for various processing tasks |
90
+ | **monitoring/** | Performance monitoring, progress tracking, error handling, logging |
91
+ | **web/** | FastAPI server, HTTP endpoints, web UI |
92
+ | **implementations/** | Framework-specific agent implementations (LlamaIndex, Microsoft) |
93
+ | **utils/** | General utilities and helpers |
94
+
95
+ ## 3. Core Components
96
+
97
+ ### a. AgentInterface (core/agent_interface.py)
98
+
99
+ The core contract that all agents must implement. Defines the standard methods for:
100
+
101
+ - `handle_message()` - Process a user message
102
+ - `handle_message_stream()` - Process with streaming response
103
+ - `get_state()` - Retrieve agent state for persistence
104
+ - `load_state()` - Load persisted state
105
+ - `configure_session()` - Configure session parameters
106
+ - `get_metadata()` - Return agent metadata
107
+
108
+ **Key Principle**: Any agent framework can be integrated by implementing this interface.
109
+
110
+ ### b. BaseAgent (core/base_agent.py)
111
+
112
+ A generic base class that provides common functionality for all agents:
113
+
114
+ - Session management
115
+ - State serialization/deserialization
116
+ - Configuration handling
117
+ - Metadata management
118
+
119
+ Concrete agents can inherit from `BaseAgent` to get these features automatically.
120
+
121
+ ### c. AgentManager (core/agent_provider.py)
122
+
123
+ The "wrapper" or provider that manages the lifecycle of agents:
124
+
125
+ - **Creation**: Instantiates agents on demand
126
+ - **State Loading**: Loads persisted state from SessionStorage
127
+ - **Proxy Wrapping**: Wraps agents in `_ManagedAgentProxy` for automatic state saving
128
+ - **Validation**: Validates state compatibility using StateManager
129
+
130
+ **Key Principle**: The server never creates agents directly; it always goes through AgentManager.
131
+
132
+ ### d. _ManagedAgentProxy (core/agent_provider.py)
133
+
134
+ An internal proxy that implements `AgentInterface` and wraps the real agent:
135
+
136
+ - **Transparent**: Looks and behaves exactly like the real agent
137
+ - **Automatic State Saving**: After each message, automatically calls `get_state()` and persists to SessionStorage
138
+ - **Proxy Pattern**: Enables state persistence without server involvement
139
+
140
+ **Key Principle**: State saving is an invisible, automatic side-effect of handling a message.
141
+
142
+ ### e. StateManager (core/state_manager.py)
143
+
144
+ Handles framework-agnostic state management:
145
+
146
+ - **Compression**: Compresses large state objects for efficient storage
147
+ - **Decompression**: Decompresses state when loading
148
+ - **Identity Management**: Creates and validates agent identities
149
+ - **Compatibility**: Validates state compatibility between sessions
150
+
151
+ **Key Principle**: State is treated as opaque data; StateManager doesn't need to understand framework-specific formats.
152
+
153
+ ### f. ModelClientFactory (core/model_clients.py)
154
+
155
+ Creates LLM clients for different providers:
156
+
157
+ - **OpenAI**: Creates AsyncOpenAI clients
158
+ - **Anthropic**: Creates AsyncAnthropic clients
159
+ - **Gemini**: Creates Google Generative AI clients
160
+ - **LlamaIndex**: Creates LlamaIndex LLM instances with proper imports
161
+ - **Parameter Handling**: Filters provider-specific parameters
162
+ - **Error Recovery**: Retries without unsupported parameters
163
+
164
+ **Key Principle**: Centralizes all LLM client creation logic, making it easy to add new providers.
165
+
166
+ ### g. SessionStorage (session/session_storage.py)
167
+
168
+ The persistence layer with two distinct responsibilities:
169
+
170
+ 1. **Session Metadata**: Lightweight session information (user_id, timestamps, correlation_id)
171
+ 2. **Agent State**: Potentially large agent state blobs
172
+
173
+ **Implementations**:
174
+ - **MemorySessionStorage**: In-memory storage for development
175
+ - **MongoDBSessionStorage**: MongoDB storage for production
176
+
177
+ **Key Principle**: Session metadata and agent state are separate concerns with separate storage.
178
+
179
+ ### h. Server (web/server.py)
180
+
181
+ The FastAPI web server that:
182
+
183
+ - **Handles HTTP Requests**: Processes incoming API calls
184
+ - **Delegates to AgentManager**: Never creates or manages agents directly
185
+ - **Returns Responses**: Formats and returns responses to clients
186
+ - **Framework-Agnostic**: No knowledge of specific agent frameworks
187
+
188
+ **Key Principle**: The server is a thin layer that orchestrates high-level workflows.
189
+
190
+ ## 4. Key Architectural Decisions & Principles
191
+
192
+ ### a. True Decoupling via AgentManager
193
+
194
+ The server does not create agent instances or load their state directly. Instead, it delegates this entire responsibility to the `AgentManager`. This manager is the only component that understands how to assemble a fully functional agent, abstracting away all complexity from the server.
195
+
196
+ ### b. The Proxy Pattern for Transparent State Management
197
+
198
+ A critical requirement was that state should be persisted automatically after an agent responds, without the server needing to explicitly trigger a "save" operation. We achieve this using the **Proxy Pattern**.
199
+
200
+ - The `AgentManager` does not return the `RealAgent` to the server. It returns a `_ManagedAgentProxy` instead.
201
+ - This proxy *looks and feels* exactly like a real agent because it implements the same `AgentInterface`.
202
+ - When the server calls `handle_message()` on the proxy, the proxy first passes the call to the `RealAgent`.
203
+ - Once the `RealAgent` returns a response, the proxy automatically calls the agent's `get_state()` method and instructs the `SessionStorage` to persist the new state.
204
+
205
+ This makes state saving an invisible, automatic side-effect of handling a message, dramatically simplifying the server logic.
206
+
207
+ ### c. Separation of Agent State from Session Metadata
208
+
209
+ An agent's internal state (its memory, configuration, etc.) is a fundamentally different concern from the session's metadata (user ID, timestamps, correlation ID).
210
+
211
+ This architecture formalizes that separation. The `SessionStorage` interface has distinct methods for:
212
+
213
+ 1. `save_session()` / `load_session()`: For lightweight session metadata
214
+ 2. `save_agent_state()` / `load_agent_state()`: For potentially large agent state blobs
215
+
216
+ This ensures the system is more organized, scalable, and easier to debug.
217
+
218
+ ### d. Interface-Driven Design for Extensibility
219
+
220
+ The `AgentInterface` is the core contract that enables the entire system's flexibility. Any future agent, regardless of its underlying framework, can be integrated into the system by simply:
221
+
222
+ 1. Implementing the `AgentInterface`
223
+ 2. Providing the logic for its own state management within the `get_state()` and `load_state()` methods
224
+
225
+ The server, `AgentManager`, and `SessionStorage` layers will require no changes.
226
+
227
+ ### e. Framework-Specific Implementations
228
+
229
+ The `implementations/` folder contains framework-specific agent classes:
230
+
231
+ **LlamaIndexAgent** (implementations/llamaindex_agent.py):
232
+ - Integrates with LlamaIndex framework
233
+ - Handles LlamaIndex-specific agent creation and configuration
234
+ - Manages LlamaIndex state serialization
235
+ - Provides simple interface: implement `get_agent_prompt()` and `get_agent_tools()`
236
+
237
+ **MicrosoftAgent** (implementations/microsoft_agent.py):
238
+ - Integrates with Microsoft Agent Framework
239
+ - Handles Microsoft-specific agent creation and configuration
240
+ - Manages Microsoft state serialization
241
+
242
+ **Key Principle**: Framework-specific code is isolated in implementations/, keeping the core framework clean.
243
+
244
+ ## 5. Workflows & Sequence Diagrams
245
+
246
+ ### Workflow 1: Full Session Lifecycle
247
+
248
+ ```mermaid
249
+ sequenceDiagram
250
+ participant User as User/Client
251
+ participant Server as Server (FastAPI)
252
+ participant AgentManager as AgentManager
253
+ participant Proxy as _ManagedAgentProxy
254
+ participant Agent as Concrete Agent
255
+ participant SessionStorage as SessionStorage
256
+ participant StateManager as StateManager
257
+
258
+ Note over User, StateManager: Initialize Session
259
+
260
+ User->>+Server: POST /init (config)
261
+ Server->>AgentManager: init_session(user_id, config)
262
+ AgentManager->>SessionStorage: save_session(session_metadata)
263
+ AgentManager->>SessionStorage: save_agent_state(session_id, empty_state)
264
+ Server-->>-User: 200 OK (session_id)
265
+
266
+ Note over User, StateManager: Send Message
267
+
268
+ User->>+Server: POST /message (session_id, input)
269
+ Server->>AgentManager: get_agent(session_id, agent_class)
270
+ AgentManager->>SessionStorage: load_agent_state(session_id)
271
+ SessionStorage-->>AgentManager: returns stored_state
272
+ AgentManager->>Agent: new ConcreteAgent()
273
+ AgentManager->>Agent: load_state(stored_state)
274
+ Agent->>StateManager: decompress_state(...)
275
+ AgentManager->>Proxy: new _ManagedAgentProxy(agent)
276
+ AgentManager-->>Server: returns proxy_instance
277
+
278
+ Server->>Proxy: handle_message(input)
279
+ Proxy->>Agent: handle_message(input)
280
+ Agent-->>Proxy: returns response
281
+
282
+ Note over Proxy, StateManager: Automatic State Persistence
283
+
284
+ Proxy->>Agent: get_state()
285
+ Agent->>StateManager: compress_state(...)
286
+ Agent-->>Proxy: returns new_state
287
+ Proxy->>SessionStorage: save_agent_state(session_id, new_state)
288
+ Proxy-->>Server: returns response
289
+ Server-->>-User: 200 OK (response)
290
+
291
+ Note over User, StateManager: End Session
292
+
293
+ User->>+Server: POST /end (session_id)
294
+ Server->>AgentManager: end_session(session_id)
295
+ AgentManager->>SessionStorage: update_session_status('closed')
296
+ Server-->>-User: 200 OK
297
+ ```
298
+
299
+ ### Workflow 2: Stateless Endpoints
300
+
301
+ ```mermaid
302
+ sequenceDiagram
303
+ participant User as User/Client
304
+ participant Server as Server (FastAPI)
305
+ participant Agent as Concrete Agent
306
+
307
+ User->>+Server: GET /metadata
308
+ Note over Server, Agent: Stateless - no AgentManager needed
309
+ Server->>Agent: new Agent() (temporary)
310
+ Server->>Agent: get_metadata()
311
+ Agent-->>Server: returns metadata
312
+ Server-->>-User: 200 OK (metadata)
313
+ ```
314
+
315
+ ## 6. Data Models
316
+
317
+ ### AgentIdentity
318
+
319
+ ```python
320
+ @dataclass
321
+ class AgentIdentity:
322
+ agent_id: str # UUID
323
+ agent_type: str # Class name
324
+ agent_class: str # Full class path
325
+ config_hash: str # Configuration hash
326
+ created_at: datetime
327
+ metadata: Dict[str, Any]
328
+ ```
329
+
330
+ ### SessionData
331
+
332
+ ```python
333
+ @dataclass
334
+ class SessionData:
335
+ session_id: str
336
+ user_id: str
337
+ agent_instance_config: Dict[str, Any]
338
+ correlation_id: Optional[str] = None
339
+ created_at: Optional[str] = None
340
+ updated_at: Optional[str] = None
341
+ metadata: Optional[Dict[str, Any]] = None
342
+ agent_id: Optional[str] = None
343
+ agent_type: Optional[str] = None
344
+ session_configuration: Optional[Dict[str, Any]] = None
345
+ session_label: Optional[str] = None
346
+ ```
347
+
348
+ ### MessageData
349
+
350
+ ```python
351
+ @dataclass
352
+ class MessageData:
353
+ message_id: str
354
+ session_id: str
355
+ user_id: str
356
+ interaction_id: str
357
+ sequence_number: int
358
+ message_type: str # "user_input" or "agent_response"
359
+ role: str
360
+ text_content: Optional[str] = None
361
+ parts: Optional[List[Dict[str, Any]]] = None
362
+ response_text_main: Optional[str] = None
363
+ # ... timestamps, metadata, etc.
364
+ ```
365
+
366
+ ## 7. Component Details
367
+
368
+ ### Core Components
369
+
370
+ #### agent_interface.py
371
+ - **Purpose**: Defines the contract all agents must implement
372
+ - **Key Methods**: handle_message, handle_message_stream, get_state, load_state
373
+ - **Design**: Abstract base class ensuring consistent agent behavior
374
+
375
+ #### base_agent.py
376
+ - **Purpose**: Provides common functionality for all agents
377
+ - **Features**: Session management, state serialization, configuration handling
378
+ - **Usage**: Concrete agents inherit from BaseAgent
379
+
380
+ #### agent_provider.py (AgentManager)
381
+ - **Purpose**: Manages agent lifecycle
382
+ - **Responsibilities**: Creation, state loading, proxy wrapping, validation
383
+ - **Pattern**: Factory + Proxy pattern
384
+
385
+ #### state_manager.py
386
+ - **Purpose**: Framework-agnostic state management
387
+ - **Features**: Compression, decompression, identity management, compatibility validation
388
+ - **Design**: Treats state as opaque data
389
+
390
+ #### model_config.py
391
+ - **Purpose**: Multi-provider model configuration
392
+ - **Providers**: OpenAI, Anthropic, Gemini
393
+ - **Features**: Provider detection, parameter validation, configuration merging
394
+
395
+ #### model_clients.py
396
+ - **Purpose**: LLM client factory
397
+ - **Methods**: create_openai_client, create_anthropic_client, create_gemini_client, create_llamaindex_llm
398
+ - **Features**: Parameter filtering, error recovery, provider-specific handling
399
+
400
+ ### Session Components
401
+
402
+ #### session_storage.py
403
+ - **Purpose**: Session and state persistence
404
+ - **Implementations**: MemorySessionStorage, MongoDBSessionStorage
405
+ - **Design**: Separates session metadata from agent state
406
+
407
+ ### Storage Components
408
+
409
+ #### file_storages.py
410
+ - **Purpose**: File storage backends
411
+ - **Backends**: Local, S3, MinIO
412
+ - **Features**: Multi-backend support, intelligent routing
413
+
414
+ #### file_system_management.py
415
+ - **Purpose**: File storage orchestration
416
+ - **Features**: Upload, download, metadata management, backend selection
417
+
418
+ #### storage_optimizer.py
419
+ - **Purpose**: Storage optimization
420
+ - **Features**: Compression, deduplication, cleanup
421
+
422
+ ### Web Components
423
+
424
+ #### server.py
425
+ - **Purpose**: FastAPI web server
426
+ - **Endpoints**: /message, /stream, /init, /end, /sessions, /config, /files
427
+ - **Design**: Framework-agnostic, delegates to AgentManager
428
+ - **Features**: Authentication, CORS, error handling, streaming
429
+
430
+ ## 8. Extension Points
431
+
432
+ ### Adding a New Agent Framework
433
+
434
+ To add support for a new agent framework:
435
+
436
+ 1. **Create Implementation**: Add a new file in `implementations/` (e.g., `langchain_agent.py`)
437
+ 2. **Implement AgentInterface**: Implement all required methods
438
+ 3. **Handle State**: Implement `get_state()` and `load_state()` for your framework
439
+ 4. **Export**: Add to `implementations/__init__.py`
440
+ 5. **Document**: Add usage examples and documentation
441
+
442
+ **No changes needed to**:
443
+ - Core framework
444
+ - Server
445
+ - SessionStorage
446
+ - AgentManager
447
+
448
+ ### Adding a New Storage Backend
449
+
450
+ To add a new storage backend:
451
+
452
+ 1. **Implement Interface**: Implement the storage backend interface in `storage/file_storages.py`
453
+ 2. **Add Configuration**: Add configuration options in `model_config.py`
454
+ 3. **Register**: Register the backend in FileStorageManager
455
+ 4. **Test**: Add tests in `tests/test_storage/`
456
+
457
+ ### Adding a New LLM Provider
458
+
459
+ To add a new LLM provider:
460
+
461
+ 1. **Add to ModelConfig**: Add provider enum and configuration in `model_config.py`
462
+ 2. **Add Client Factory**: Add creation method in `model_clients.py`
463
+ 3. **Handle Parameters**: Add provider-specific parameter handling
464
+ 4. **Test**: Add tests for the new provider
465
+
466
+ ## 9. Design Patterns Used
467
+
468
+ | Pattern | Where Used | Purpose |
469
+ |---------|-----------|---------|
470
+ | **Proxy** | _ManagedAgentProxy | Automatic state persistence |
471
+ | **Factory** | ModelClientFactory | LLM client creation |
472
+ | **Strategy** | AgentInterface | Pluggable agent implementations |
473
+ | **Template Method** | BaseAgent | Common agent functionality |
474
+ | **Singleton** | AgentManager | Single agent lifecycle manager |
475
+ | **Repository** | SessionStorage | Data persistence abstraction |
476
+
477
+ ## 10. Performance Considerations
478
+
479
+ ### State Compression
480
+
481
+ - **Problem**: Agent state can be large (conversation history, embeddings)
482
+ - **Solution**: StateManager compresses state before persistence
483
+ - **Benefit**: Reduced storage costs and faster I/O
484
+
485
+ ### Lazy Loading
486
+
487
+ - **Problem**: Loading all agent state upfront is expensive
488
+ - **Solution**: Agents load state on-demand
489
+ - **Benefit**: Faster startup and lower memory usage
490
+
491
+ ### Connection Pooling
492
+
493
+ - **Problem**: Creating new database connections is slow
494
+ - **Solution**: MongoDB connection pooling
495
+ - **Benefit**: Better performance under load
496
+
497
+ ### Caching
498
+
499
+ - **Problem**: Repeated model configuration lookups
500
+ - **Solution**: Cache model configurations
501
+ - **Benefit**: Reduced latency
502
+
503
+ ## 11. Security Considerations
504
+
505
+ ### Authentication
506
+
507
+ - **Basic Auth**: Username/password authentication
508
+ - **API Keys**: Bearer token authentication
509
+ - **Configurable**: Can be enabled/disabled via environment variables
510
+
511
+ ### Input Validation
512
+
513
+ - **Pydantic Models**: All inputs validated with Pydantic
514
+ - **Type Safety**: Strong typing throughout
515
+ - **Sanitization**: User inputs sanitized before processing
516
+
517
+ ### State Isolation
518
+
519
+ - **Session Isolation**: Each session has isolated state
520
+ - **User Isolation**: Users cannot access other users' sessions
521
+ - **Agent Identity**: Agents validate state compatibility
522
+
523
+ ## 12. Monitoring & Observability
524
+
525
+ ### Logging
526
+
527
+ - **Structured Logging**: JSON-formatted logs
528
+ - **Log Levels**: DEBUG, INFO, WARNING, ERROR
529
+ - **Context**: All logs include session_id, user_id, correlation_id
530
+
531
+ ### Performance Monitoring
532
+
533
+ - **Metrics**: Request latency, throughput, error rates
534
+ - **Resource Tracking**: Memory, CPU, storage usage
535
+ - **Progress Tracking**: Long-running operation progress
536
+
537
+ ### Error Handling
538
+
539
+ - **Structured Errors**: Consistent error format
540
+ - **Error Logging**: All errors logged with context
541
+ - **Graceful Degradation**: System continues operating on non-critical errors
542
+
543
+ ## 13. Testing Strategy
544
+
545
+ ### Unit Tests
546
+
547
+ - **Core Components**: Test each component in isolation
548
+ - **Mocking**: Mock external dependencies
549
+ - **Coverage**: >80% code coverage target
550
+
551
+ ### Integration Tests
552
+
553
+ - **End-to-End**: Test complete workflows
554
+ - **Multiple Frameworks**: Test with LlamaIndex and Microsoft agents
555
+ - **Storage Backends**: Test with Memory and MongoDB storage
556
+
557
+ ### Performance Tests
558
+
559
+ - **Load Testing**: Test under high load
560
+ - **Stress Testing**: Test system limits
561
+ - **Benchmarking**: Compare performance across versions
562
+
563
+ ## 14. Future Enhancements
564
+
565
+ ### Planned Features
566
+
567
+ - **Multi-Agent Orchestration**: Built-in support for agent teams
568
+ - **Streaming Improvements**: Enhanced streaming with backpressure
569
+ - **Advanced Caching**: Semantic caching for LLM responses
570
+ - **Observability**: OpenTelemetry integration
571
+ - **Horizontal Scaling**: Distributed agent management
572
+
573
+ ### Extension Points
574
+
575
+ - **Custom Middleware**: Plugin system for custom middleware
576
+ - **Custom Storage**: Easy addition of new storage backends
577
+ - **Custom Providers**: Easy addition of new LLM providers
578
+ - **Custom Tools**: Plugin system for agent tools
579
+
580
+ ---
581
+
582
+ This architecture provides a solid foundation for building scalable, maintainable, and extensible AI agent applications across multiple frameworks.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Agent Framework Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,78 @@
1
+ # Include essential documentation and configuration files
2
+ include README.md
3
+ include LICENSE
4
+ include pyproject.toml
5
+ include ARCHITECTURE.md
6
+
7
+ # Include documentation from docs directory
8
+ include docs/CHANGELOG.md
9
+ include docs/*.md
10
+
11
+ # Include type information
12
+ include agent_framework/py.typed
13
+
14
+ # Include HTML templates and static files from the main package
15
+ include agent_framework/test_app.html
16
+ include agent_framework/*.html
17
+ include agent_framework/*.json
18
+ include agent_framework/*.yaml
19
+ include agent_framework/*.yml
20
+ include agent_framework/*.css
21
+ include agent_framework/*.js
22
+
23
+ # Include HTML files from web subdirectory (for /ui endpoint)
24
+ recursive-include agent_framework/web *.html
25
+ recursive-include agent_framework/web *.css
26
+ recursive-include agent_framework/web *.js
27
+
28
+ # Include documentation files from web/docs (Dockerfile, docker-compose, markdown)
29
+ recursive-include agent_framework/web/docs *.md
30
+ recursive-include agent_framework/web/docs *.py
31
+ include agent_framework/web/docs/Dockerfile
32
+ include agent_framework/web/docs/docker-compose.yml
33
+
34
+ # Include specific example files but exclude large dependencies
35
+ include examples/*.py
36
+ include examples/*.md
37
+ include examples/*.txt
38
+ include examples/*.toml
39
+ include examples/*.env
40
+ include examples/requirements.txt
41
+ include examples/pyproject.toml
42
+ recursive-include examples/dependencies *.yaml
43
+ recursive-include examples/dependencies *.yml
44
+
45
+ # Exclude development and cache files
46
+ exclude .gitignore
47
+ exclude *.code-workspace
48
+ exclude package-lock.json
49
+ exclude uv.lock
50
+ recursive-exclude * __pycache__
51
+ recursive-exclude * *.py[co]
52
+ recursive-exclude * *.pyo
53
+ recursive-exclude * .DS_Store
54
+
55
+ # Exclude entire directories
56
+ recursive-exclude .git *
57
+ recursive-exclude .vscode *
58
+ recursive-exclude .cursor *
59
+ recursive-exclude .pytest_cache *
60
+ recursive-exclude specs *
61
+ recursive-exclude .venv *
62
+ recursive-exclude mcp-server *
63
+ recursive-exclude tests *
64
+
65
+ # CRITICAL: Exclude heavy node_modules and similar directories
66
+ recursive-exclude examples/node_modules *
67
+ recursive-exclude node_modules *
68
+ recursive-exclude */node_modules *
69
+
70
+ # Exclude other development directories
71
+ prune .git
72
+ prune .vscode
73
+ prune .cursor
74
+ prune specs
75
+ prune .venv
76
+ prune node_modules
77
+ prune mcp-server
78
+ prune examples/node_modules