agent-framework-lib 0.1.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 (27) hide show
  1. agent_framework_lib-0.1.0/ARCHITECTURE.md +120 -0
  2. agent_framework_lib-0.1.0/CHANGELOG.md +78 -0
  3. agent_framework_lib-0.1.0/LICENSE +21 -0
  4. agent_framework_lib-0.1.0/MANIFEST.in +63 -0
  5. agent_framework_lib-0.1.0/PKG-INFO +1267 -0
  6. agent_framework_lib-0.1.0/README.md +1205 -0
  7. agent_framework_lib-0.1.0/agent_framework/__init__.py +185 -0
  8. agent_framework_lib-0.1.0/agent_framework/agent_interface.py +314 -0
  9. agent_framework_lib-0.1.0/agent_framework/agent_provider.py +124 -0
  10. agent_framework_lib-0.1.0/agent_framework/autogen_state_manager.py +417 -0
  11. agent_framework_lib-0.1.0/agent_framework/model_clients.py +313 -0
  12. agent_framework_lib-0.1.0/agent_framework/model_config.py +255 -0
  13. agent_framework_lib-0.1.0/agent_framework/server.py +1383 -0
  14. agent_framework_lib-0.1.0/agent_framework/session_storage.py +1445 -0
  15. agent_framework_lib-0.1.0/agent_framework/test_app.html +5262 -0
  16. agent_framework_lib-0.1.0/agent_framework_lib.egg-info/PKG-INFO +1267 -0
  17. agent_framework_lib-0.1.0/agent_framework_lib.egg-info/SOURCES.txt +25 -0
  18. agent_framework_lib-0.1.0/agent_framework_lib.egg-info/dependency_links.txt +1 -0
  19. agent_framework_lib-0.1.0/agent_framework_lib.egg-info/requires.txt +32 -0
  20. agent_framework_lib-0.1.0/agent_framework_lib.egg-info/top_level.txt +1 -0
  21. agent_framework_lib-0.1.0/examples/README.md +395 -0
  22. agent_framework_lib-0.1.0/examples/dependencies/docker-compose.yaml +26 -0
  23. agent_framework_lib-0.1.0/examples/pyproject.toml +152 -0
  24. agent_framework_lib-0.1.0/examples/requirements.txt +16 -0
  25. agent_framework_lib-0.1.0/examples/streaming_autogen_assistant.py +758 -0
  26. agent_framework_lib-0.1.0/pyproject.toml +153 -0
  27. agent_framework_lib-0.1.0/setup.cfg +4 -0
@@ -0,0 +1,120 @@
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.
6
+
7
+ The primary architectural goal is the **Separation of Concerns**. Specifically, we aim to completely decouple the web server layer from the implementation details of any specific agent framework (e.g., Microsoft Autogen). The server should not 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 (like LangChain, etc.) in the future without modifying the core server logic.
10
+
11
+ ## 2. Core Components
12
+
13
+ The architecture is composed of several key components, each with a single, well-defined responsibility.
14
+
15
+ | Component | Responsibility |
16
+ | :--------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
17
+ | **Server (FastAPI)** | Handles HTTP requests, manages the web layer, and orchestrates high-level workflows by interacting with the `AgentManager`. |
18
+ | **AgentManager** | The "wrapper" or provider. Manages the lifecycle of agents, including creation, state loading, and wrapping them in a proxy. It is the single point of contact for the server. |
19
+ | **_ManagedAgentProxy** | An object that implements the `AgentInterface` and wraps the real agent. It transparently adds automatic state-saving behavior after a message is handled. |
20
+ | **RealAgent** | The concrete agent implementation (e.g.,StreamingAutoGenAssistant). Implements the `AgentInterface` and contains the core conversational logic. It is responsible for its own state via `get_state()` and `load_state()`. |
21
+ | **SessionStorage** | The persistence layer. Manages the storage of two distinct data types: session metadata and agent state, linked by a `session_id`. |
22
+ | **AutoGen State Mgr** | A helper module used*only* by an Autogen-based `RealAgent` to handle the specifics of serializing, compressing, and managing Autogen's unique state format. |
23
+
24
+ ## 3. Key Architectural Decisions & Principles
25
+
26
+ ### a. True Decoupling via an Agent Manager
27
+
28
+ 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.
29
+
30
+ ### b. The Proxy Pattern for Transparent State Management
31
+
32
+ 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**.
33
+
34
+ - The `AgentManager` does not return the `RealAgent` to the server. It returns a `_ManagedAgentProxy` instead.
35
+ - This proxy *looks and feels* exactly like a real agent because it implements the same `AgentInterface`.
36
+ - When the server calls `handle_message()` on the proxy, the proxy first passes the call to the `RealAgent`.
37
+ - 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.
38
+
39
+ This makes state saving an invisible, automatic side-effect of handling a message, dramatically simplifying the server logic.
40
+
41
+ ### c. Separation of Agent State from Session Metadata
42
+
43
+ Based on your insight, an agent's internal state (its memory, configuration, etc.) is a fundamentally different concern from the session's metadata (user ID, timestamps, correlation ID).
44
+
45
+ This architecture formalizes that separation. The `SessionStorage` interface has distinct methods and underlying collections/tables for:
46
+
47
+ 1. `save_session()` / `load_session()`: For lightweight session metadata.
48
+ 2. `save_agent_state()` / `load_agent_state()`: For the potentially large and complex agent state "blob".
49
+
50
+ This ensures the system is more organized, scalable, and easier to debug.
51
+
52
+ ### d. Interface-Driven Design for Extensibility
53
+
54
+ 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:
55
+
56
+ 1. Implementing the `AgentInterface`.
57
+ 2. Providing the logic for its own state management within the `get_state()` and `load_state()` methods.
58
+
59
+ The server, `AgentManager`, and `SessionStorage` layers will require no changes.
60
+
61
+ ## 4. Workflows & Sequence Diagram
62
+
63
+ The following diagram illustrates how the components interact across the main API workflows.
64
+
65
+ ```mermaid
66
+ sequenceDiagram
67
+ participant User as User/Client
68
+ participant Server as Server (FastAPI)
69
+ participant AgentManager as AgentManager
70
+ participant _ManagedAgentProxy as AgentProxy
71
+ participant RealAgent as RealAgent
72
+ participant SessionStorage as SessionStorage
73
+ participant AutoGenStateManager as AutoGen State Mgr
74
+
75
+ Note over User, AutoGenStateManager: Workflow 1: Full Session (/init -> /message -> /end)
76
+
77
+ User->>+Server: POST /init (config)
78
+ Note over Server,AgentManager: Server creates AgentManager at startup. The manager has access to SessionStorage.
79
+ Server->>AgentManager: init_session(user_id, config)
80
+ AgentManager->>SessionStorage: save_session(session_metadata)
81
+ AgentManager->>SessionStorage: save_agent_state(session_id, empty_state)
82
+ Server-->>-User: 200 OK (session_id)
83
+
84
+ User->>+Server: POST /message (session_id, input)
85
+ Server->>AgentManager: get_agent(session_id, agent_class)
86
+ AgentManager->>SessionStorage: load_agent_state(session_id)
87
+ SessionStorage-->>AgentManager: returns stored_state
88
+ AgentManager->>RealAgent: new RealAgent()
89
+ AgentManager->>RealAgent: load_state(stored_state)
90
+ Note right of RealAgent: Agent uses its specific State Manager internally to decompress/load state.
91
+ RealAgent->>AutoGenStateManager: decompress_state(...)
92
+ AgentManager->>_ManagedAgentProxy: new _ManagedAgentProxy(real_agent)
93
+ Note over AgentManager,_ManagedAgentProxy: Proxy implements AgentInterface, hiding the real agent from the server.
94
+ AgentManager-->>Server: returns proxy_instance
95
+
96
+ Server->>_ManagedAgentProxy: handle_message(input)
97
+ _ManagedAgentProxy->>RealAgent: handle_message(input)
98
+ RealAgent-->>_ManagedAgentProxy: returns response
99
+ Note over _ManagedAgentProxy,RealAgent: Automatic State Persistence (Proxy Pattern)
100
+ _ManagedAgentProxy->>RealAgent: get_state()
101
+ RealAgent->>AutoGenStateManager: compress_state(...)
102
+ RealAgent-->>_ManagedAgentProxy: returns new_state
103
+ _ManagedAgentProxy->>SessionStorage: save_agent_state(session_id, new_state)
104
+ _ManagedAgentProxy-->>Server: returns response
105
+ Server-->>-User: 200 OK (response)
106
+
107
+ User->>+Server: POST /end (session_id)
108
+ Server->>AgentManager: end_session(session_id)
109
+ AgentManager->>SessionStorage: update_session_status('closed')
110
+ Server-->>-User: 200 OK
111
+
112
+ Note over User, AutoGenStateManager: Workflow 2: Stateless Endpoints (e.g., /metadata)
113
+
114
+ User->>+Server: GET /metadata
115
+ Note over Server,RealAgent: This flow is stateless and doesn't need the AgentManager or persistence.
116
+ Server->>RealAgent: new RealAgent() (temporary instance)
117
+ Server->>RealAgent: get_metadata()
118
+ RealAgent-->>Server: returns metadata
119
+ Server-->>-User: 200 OK (metadata)
120
+ ```
@@ -0,0 +1,78 @@
1
+ # Changelog
2
+
3
+ All notable changes to the Agent Framework will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2025-01-XX
11
+
12
+ ### Added
13
+ - Initial release of Agent Framework
14
+ - **Core Framework Features:**
15
+ - Abstract `AgentInterface` for building custom agents
16
+ - FastAPI-based server with automatic session management
17
+ - Multi-provider AI model support (OpenAI, Gemini)
18
+ - Automatic model routing and configuration
19
+ - Session-based conversation handling with persistence
20
+ - Streaming response support
21
+ - Multi-modal input support (text, images, files)
22
+
23
+ - **Session Management:**
24
+ - Memory-based and MongoDB session storage backends
25
+ - Automatic agent state persistence using proxy pattern
26
+ - Session workflow with init/end endpoints
27
+ - Correlation ID support for linking sessions across agents
28
+ - Session metadata and configuration management
29
+
30
+ - **Agent Features:**
31
+ - AutoGen-based base agent implementation
32
+ - System prompt configuration and templating
33
+ - Dynamic agent configuration (temperature, tokens, etc.)
34
+ - Media detection in agent responses
35
+ - Multi-agent conversation support
36
+ - MCP (Model Context Protocol) integration
37
+
38
+ - **Authentication & Security:**
39
+ - Basic authentication support
40
+ - API key authentication
41
+ - Configurable authentication requirements
42
+
43
+ - **User Experience:**
44
+ - Built-in web test interface (`/testapp`)
45
+ - User feedback system (thumbs up/down, session flags)
46
+ - Comprehensive API documentation
47
+ - Response time tracking and analytics
48
+ - Real-time streaming endpoints
49
+
50
+ - **Library Usage:**
51
+ - Convenience function `create_basic_agent_server()` for easy setup
52
+ - Pip installable from GitHub repositories
53
+ - Extensive examples and documentation
54
+
55
+ - **Developer Tools:**
56
+ - Comprehensive test suite with fixtures
57
+ - Debug logging with configurable levels
58
+ - Model configuration validation endpoints
59
+ - MongoDB integration with automatic indexing
60
+ - Docker support and examples
61
+
62
+ ### Dependencies
63
+ - fastapi>=0.115.12
64
+ - autogen-agentchat>=0.6.3
65
+ - autogen-core>=0.6.3
66
+ - autogen-ext[mcp,openai]>=0.6.3
67
+ - uvicorn>=0.34.2
68
+ - pymongo>=4.10.1
69
+ - motor>=3.6.0
70
+ - And other supporting libraries
71
+
72
+ ### Requirements
73
+ - Python 3.10 or higher
74
+ - Optional: MongoDB for persistent session storage
75
+ - API keys for OpenAI and/or Gemini models
76
+
77
+ [Unreleased]: https://github.com/Cinco-AI/AgentFramework/compare/v0.1.0...HEAD
78
+ [0.1.0]: https://github.com/Cinco-AI/AgentFramework/releases/tag/v0.1.0
@@ -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,63 @@
1
+ # Include essential documentation and configuration files
2
+ include README.md
3
+ include CHANGELOG.md
4
+ include LICENSE
5
+ include pyproject.toml
6
+
7
+ # Include architecture documentation
8
+ include ARCHITECTURE.md
9
+
10
+ # Include HTML templates and static files from the main package
11
+ include agent_framework/test_app.html
12
+ include agent_framework/*.html
13
+ include agent_framework/*.json
14
+ include agent_framework/*.yaml
15
+ include agent_framework/*.yml
16
+ include agent_framework/*.css
17
+ include agent_framework/*.js
18
+
19
+ # Include specific example files but exclude large dependencies
20
+ include examples/*.py
21
+ include examples/*.md
22
+ include examples/*.txt
23
+ include examples/*.toml
24
+ include examples/*.env
25
+ include examples/requirements.txt
26
+ include examples/pyproject.toml
27
+ recursive-include examples/dependencies *.yaml
28
+ recursive-include examples/dependencies *.yml
29
+
30
+ # Exclude development and cache files
31
+ exclude .gitignore
32
+ exclude *.code-workspace
33
+ exclude package-lock.json
34
+ exclude uv.lock
35
+ recursive-exclude * __pycache__
36
+ recursive-exclude * *.py[co]
37
+ recursive-exclude * *.pyo
38
+ recursive-exclude * .DS_Store
39
+
40
+ # Exclude entire directories
41
+ recursive-exclude .git *
42
+ recursive-exclude .vscode *
43
+ recursive-exclude .cursor *
44
+ recursive-exclude .pytest_cache *
45
+ recursive-exclude specs *
46
+ recursive-exclude .venv *
47
+ recursive-exclude mcp-server *
48
+ recursive-exclude tests *
49
+
50
+ # CRITICAL: Exclude heavy node_modules and similar directories
51
+ recursive-exclude examples/node_modules *
52
+ recursive-exclude node_modules *
53
+ recursive-exclude */node_modules *
54
+
55
+ # Exclude other development directories
56
+ prune .git
57
+ prune .vscode
58
+ prune .cursor
59
+ prune specs
60
+ prune .venv
61
+ prune node_modules
62
+ prune mcp-server
63
+ prune examples/node_modules