realtimex-services-api 0.1.6__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.
- realtimex_services_api-0.1.6/PKG-INFO +153 -0
- realtimex_services_api-0.1.6/README.md +134 -0
- realtimex_services_api-0.1.6/pyproject.toml +34 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/__init__.py +11 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/cli.py +15 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/main.py +49 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/modules/__init__.py +6 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/modules/a2a_agents/__init__.py +10 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/modules/a2a_agents/api.py +107 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/modules/agent_flows/__init__.py +10 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/modules/agent_flows/api.py +183 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/modules/agent_flows/dependencies.py +89 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/modules/agent_flows/exceptions.py +68 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/modules/agent_flows/schemas.py +98 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/modules/agent_flows/service.py +507 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/modules/agent_flows/utils/__init__.py +6 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/modules/agent_flows/utils/flow_processing.py +87 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/modules/agent_flows/utils/streaming.py +94 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/modules/python_interpreter/__init__.py +10 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/modules/python_interpreter/api.py +150 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/telemetry/__init__.py +5 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/telemetry/tracing.py +58 -0
- realtimex_services_api-0.1.6/src/realtimex_services_api/utils.py +174 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: realtimex-services-api
|
|
3
|
+
Version: 0.1.6
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Author: rta_phuongnguyen
|
|
6
|
+
Author-email: rta_phuongnguyen <phuongnguyen@rtanalytics.vn>
|
|
7
|
+
Requires-Dist: fastapi
|
|
8
|
+
Requires-Dist: uvicorn
|
|
9
|
+
Requires-Dist: realtimex-agent-flows-mcp-server
|
|
10
|
+
Requires-Dist: dotenv
|
|
11
|
+
Requires-Dist: realtimex-agent-flows-builder
|
|
12
|
+
Requires-Dist: realtimex-agent-a2a-agent
|
|
13
|
+
Requires-Dist: arize-phoenix-otel
|
|
14
|
+
Requires-Dist: openinference-instrumentation-langchain
|
|
15
|
+
Requires-Dist: openinference-instrumentation-mcp
|
|
16
|
+
Requires-Dist: litellm==1.77.1
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# RealTimeX Services API
|
|
21
|
+
|
|
22
|
+
A production-ready FastAPI application providing commonly used services in a maintainable, modular structure. This project is built on a feature-based architecture to ensure scalability and clear separation of concerns.
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- **Agent Flows**: A self-contained module providing testing, validation, and streaming endpoints for flow execution.
|
|
27
|
+
- **Feature-Based Modular Architecture**: Code is organized by business domain (e.g., "agent flows") for high cohesion and low coupling.
|
|
28
|
+
- **Production Ready**: Proper error handling, type hints, and dependency management.
|
|
29
|
+
- **Health Monitoring**: Built-in health check endpoints for observability.
|
|
30
|
+
- **API Versioning**: Endpoints are versioned (e.g., `/api/v1/...`) for long-term stability.
|
|
31
|
+
- **OpenAPI Documentation**: Auto-generated and interactive API documentation.
|
|
32
|
+
|
|
33
|
+
## Project Structure
|
|
34
|
+
|
|
35
|
+
The project follows a feature-based (vertical slice) architecture. All code related to a specific business domain is co-located within a "module".
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
src/realtimex_services_api/
|
|
39
|
+
├── __init__.py
|
|
40
|
+
├── main.py # FastAPI app initialization and router inclusion
|
|
41
|
+
├── cli.py # CLI entry point
|
|
42
|
+
├── core/ # Shared application-wide logic (config, dependencies)
|
|
43
|
+
└── modules/ # Top-level directory for all feature modules
|
|
44
|
+
├── __init__.py
|
|
45
|
+
└── agent_flows/ # A self-contained module for the "Agent Flows" feature
|
|
46
|
+
├── __init__.py
|
|
47
|
+
├── api.py # FastAPI router and HTTP-related logic
|
|
48
|
+
├── service.py # Core business logic, decoupled from the web framework
|
|
49
|
+
├── schemas.py # Pydantic models and data contracts
|
|
50
|
+
└── utils/ # Utility functions specific to this module
|
|
51
|
+
├── __init__.py
|
|
52
|
+
└── ...
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Install dependencies
|
|
59
|
+
uv sync
|
|
60
|
+
|
|
61
|
+
# Or using pip
|
|
62
|
+
pip install -e .
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Usage
|
|
66
|
+
|
|
67
|
+
### Running the Server
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# Using the CLI command
|
|
71
|
+
realtimex-services-api
|
|
72
|
+
|
|
73
|
+
# Or directly with Python
|
|
74
|
+
python -m realtimex_services_api.cli
|
|
75
|
+
|
|
76
|
+
# Or with uvicorn directly
|
|
77
|
+
uvicorn realtimex_services_api.main:app --host 0.0.0.0 --port 8004
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### API Endpoints
|
|
81
|
+
|
|
82
|
+
- **GET /** - Root endpoint with service information
|
|
83
|
+
- **GET /health** - Health check for monitoring
|
|
84
|
+
- **GET /docs** - OpenAPI documentation (Swagger UI)
|
|
85
|
+
- **GET /redoc** - Alternative API documentation
|
|
86
|
+
- **POST /api/v1/agent-flows/action/test** - Execute flow in test mode
|
|
87
|
+
- **POST /api/v1/agent-flows/action/validate** - Validate flow configuration
|
|
88
|
+
- **POST /api/v1/agent-flows/chat/stream** - Stream chat responses
|
|
89
|
+
|
|
90
|
+
## Development
|
|
91
|
+
|
|
92
|
+
### Adding a New Feature Module
|
|
93
|
+
|
|
94
|
+
The architecture makes adding new, independent features straightforward.
|
|
95
|
+
|
|
96
|
+
1. **Create the Module Directory**:
|
|
97
|
+
Create a new folder inside `src/realtimex_services_api/modules/`.
|
|
98
|
+
```bash
|
|
99
|
+
mkdir src/realtimex_services_api/modules/new_feature
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
2. **Create Standard Files**:
|
|
103
|
+
Inside the new directory, create the essential files: `__init__.py`, `api.py` (for the router), `service.py` (for business logic), and `schemas.py` (for Pydantic models).
|
|
104
|
+
|
|
105
|
+
3. **Implement the Logic**:
|
|
106
|
+
- Define your FastAPI router in `api.py`.
|
|
107
|
+
- Write your business logic in `service.py`, keeping it decoupled from FastAPI.
|
|
108
|
+
- Define your request/response models in `schemas.py`.
|
|
109
|
+
|
|
110
|
+
4. **Include the Router in `main.py`**:
|
|
111
|
+
Import and include the new router from your module's `api.py` file.
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
# In main.py
|
|
115
|
+
from .modules.new_feature.api import router as new_feature_router
|
|
116
|
+
|
|
117
|
+
app.include_router(
|
|
118
|
+
new_feature_router,
|
|
119
|
+
prefix="/api/v1/new-feature",
|
|
120
|
+
tags=["New Feature"]
|
|
121
|
+
)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Code Standards
|
|
125
|
+
|
|
126
|
+
- **Type Hints**: All functions should include proper type annotations.
|
|
127
|
+
- **Docstrings**: Public functions and modules should have clear docstrings.
|
|
128
|
+
- **Error Handling**: The service layer raises domain-specific exceptions; the API layer translates them into HTTP error responses.
|
|
129
|
+
- **Import Organization**: Follow PEP 8 import ordering.
|
|
130
|
+
|
|
131
|
+
## Configuration
|
|
132
|
+
|
|
133
|
+
The application reads configuration from `~/.realtimex.ai/Resources/server/.env.development`:
|
|
134
|
+
|
|
135
|
+
- `LLM_PROVIDER`: openai, realtimexai, or ollama
|
|
136
|
+
- `OPEN_AI_KEY`: OpenAI API key (when using openai provider)
|
|
137
|
+
- `REALTIMEX_AI_BASE_PATH`: Base URL for RealTimeX AI
|
|
138
|
+
- `REALTIMEX_AI_API_KEY`: API key for RealTimeX AI
|
|
139
|
+
- `OLLAMA_BASE_PATH`: Base URL for Ollama
|
|
140
|
+
|
|
141
|
+
## Architecture Decisions
|
|
142
|
+
|
|
143
|
+
### Why This Structure?
|
|
144
|
+
|
|
145
|
+
1. **High Cohesion, Low Coupling**: All code for a single feature (API, logic, models) lives in one place, making it self-contained. Modules have minimal dependencies on each other.
|
|
146
|
+
2. **Scalability**: The application grows by adding new, independent modules. This prevents the complexity of the project from growing exponentially.
|
|
147
|
+
3. **Improved Developer Experience**: It's easy to find all code related to a feature. A developer can understand the scope of a feature by looking inside its module directory.
|
|
148
|
+
4. **Clear Boundaries**: The separation between the HTTP layer (`api.py`) and the business logic layer (`service.py`) is strictly enforced, improving testability and reusability.
|
|
149
|
+
5. **Easy to Refactor or Extract**: A self-contained feature module is much easier to modify, delete, or extract into its own microservice if needed.
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
Internal RealTimeX project - All rights reserved.
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# RealTimeX Services API
|
|
2
|
+
|
|
3
|
+
A production-ready FastAPI application providing commonly used services in a maintainable, modular structure. This project is built on a feature-based architecture to ensure scalability and clear separation of concerns.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Agent Flows**: A self-contained module providing testing, validation, and streaming endpoints for flow execution.
|
|
8
|
+
- **Feature-Based Modular Architecture**: Code is organized by business domain (e.g., "agent flows") for high cohesion and low coupling.
|
|
9
|
+
- **Production Ready**: Proper error handling, type hints, and dependency management.
|
|
10
|
+
- **Health Monitoring**: Built-in health check endpoints for observability.
|
|
11
|
+
- **API Versioning**: Endpoints are versioned (e.g., `/api/v1/...`) for long-term stability.
|
|
12
|
+
- **OpenAPI Documentation**: Auto-generated and interactive API documentation.
|
|
13
|
+
|
|
14
|
+
## Project Structure
|
|
15
|
+
|
|
16
|
+
The project follows a feature-based (vertical slice) architecture. All code related to a specific business domain is co-located within a "module".
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
src/realtimex_services_api/
|
|
20
|
+
├── __init__.py
|
|
21
|
+
├── main.py # FastAPI app initialization and router inclusion
|
|
22
|
+
├── cli.py # CLI entry point
|
|
23
|
+
├── core/ # Shared application-wide logic (config, dependencies)
|
|
24
|
+
└── modules/ # Top-level directory for all feature modules
|
|
25
|
+
├── __init__.py
|
|
26
|
+
└── agent_flows/ # A self-contained module for the "Agent Flows" feature
|
|
27
|
+
├── __init__.py
|
|
28
|
+
├── api.py # FastAPI router and HTTP-related logic
|
|
29
|
+
├── service.py # Core business logic, decoupled from the web framework
|
|
30
|
+
├── schemas.py # Pydantic models and data contracts
|
|
31
|
+
└── utils/ # Utility functions specific to this module
|
|
32
|
+
├── __init__.py
|
|
33
|
+
└── ...
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Install dependencies
|
|
40
|
+
uv sync
|
|
41
|
+
|
|
42
|
+
# Or using pip
|
|
43
|
+
pip install -e .
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
### Running the Server
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Using the CLI command
|
|
52
|
+
realtimex-services-api
|
|
53
|
+
|
|
54
|
+
# Or directly with Python
|
|
55
|
+
python -m realtimex_services_api.cli
|
|
56
|
+
|
|
57
|
+
# Or with uvicorn directly
|
|
58
|
+
uvicorn realtimex_services_api.main:app --host 0.0.0.0 --port 8004
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### API Endpoints
|
|
62
|
+
|
|
63
|
+
- **GET /** - Root endpoint with service information
|
|
64
|
+
- **GET /health** - Health check for monitoring
|
|
65
|
+
- **GET /docs** - OpenAPI documentation (Swagger UI)
|
|
66
|
+
- **GET /redoc** - Alternative API documentation
|
|
67
|
+
- **POST /api/v1/agent-flows/action/test** - Execute flow in test mode
|
|
68
|
+
- **POST /api/v1/agent-flows/action/validate** - Validate flow configuration
|
|
69
|
+
- **POST /api/v1/agent-flows/chat/stream** - Stream chat responses
|
|
70
|
+
|
|
71
|
+
## Development
|
|
72
|
+
|
|
73
|
+
### Adding a New Feature Module
|
|
74
|
+
|
|
75
|
+
The architecture makes adding new, independent features straightforward.
|
|
76
|
+
|
|
77
|
+
1. **Create the Module Directory**:
|
|
78
|
+
Create a new folder inside `src/realtimex_services_api/modules/`.
|
|
79
|
+
```bash
|
|
80
|
+
mkdir src/realtimex_services_api/modules/new_feature
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
2. **Create Standard Files**:
|
|
84
|
+
Inside the new directory, create the essential files: `__init__.py`, `api.py` (for the router), `service.py` (for business logic), and `schemas.py` (for Pydantic models).
|
|
85
|
+
|
|
86
|
+
3. **Implement the Logic**:
|
|
87
|
+
- Define your FastAPI router in `api.py`.
|
|
88
|
+
- Write your business logic in `service.py`, keeping it decoupled from FastAPI.
|
|
89
|
+
- Define your request/response models in `schemas.py`.
|
|
90
|
+
|
|
91
|
+
4. **Include the Router in `main.py`**:
|
|
92
|
+
Import and include the new router from your module's `api.py` file.
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
# In main.py
|
|
96
|
+
from .modules.new_feature.api import router as new_feature_router
|
|
97
|
+
|
|
98
|
+
app.include_router(
|
|
99
|
+
new_feature_router,
|
|
100
|
+
prefix="/api/v1/new-feature",
|
|
101
|
+
tags=["New Feature"]
|
|
102
|
+
)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Code Standards
|
|
106
|
+
|
|
107
|
+
- **Type Hints**: All functions should include proper type annotations.
|
|
108
|
+
- **Docstrings**: Public functions and modules should have clear docstrings.
|
|
109
|
+
- **Error Handling**: The service layer raises domain-specific exceptions; the API layer translates them into HTTP error responses.
|
|
110
|
+
- **Import Organization**: Follow PEP 8 import ordering.
|
|
111
|
+
|
|
112
|
+
## Configuration
|
|
113
|
+
|
|
114
|
+
The application reads configuration from `~/.realtimex.ai/Resources/server/.env.development`:
|
|
115
|
+
|
|
116
|
+
- `LLM_PROVIDER`: openai, realtimexai, or ollama
|
|
117
|
+
- `OPEN_AI_KEY`: OpenAI API key (when using openai provider)
|
|
118
|
+
- `REALTIMEX_AI_BASE_PATH`: Base URL for RealTimeX AI
|
|
119
|
+
- `REALTIMEX_AI_API_KEY`: API key for RealTimeX AI
|
|
120
|
+
- `OLLAMA_BASE_PATH`: Base URL for Ollama
|
|
121
|
+
|
|
122
|
+
## Architecture Decisions
|
|
123
|
+
|
|
124
|
+
### Why This Structure?
|
|
125
|
+
|
|
126
|
+
1. **High Cohesion, Low Coupling**: All code for a single feature (API, logic, models) lives in one place, making it self-contained. Modules have minimal dependencies on each other.
|
|
127
|
+
2. **Scalability**: The application grows by adding new, independent modules. This prevents the complexity of the project from growing exponentially.
|
|
128
|
+
3. **Improved Developer Experience**: It's easy to find all code related to a feature. A developer can understand the scope of a feature by looking inside its module directory.
|
|
129
|
+
4. **Clear Boundaries**: The separation between the HTTP layer (`api.py`) and the business logic layer (`service.py`) is strictly enforced, improving testability and reusability.
|
|
130
|
+
5. **Easy to Refactor or Extract**: A self-contained feature module is much easier to modify, delete, or extract into its own microservice if needed.
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
Internal RealTimeX project - All rights reserved.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "realtimex-services-api"
|
|
3
|
+
version = "0.1.6"
|
|
4
|
+
description = "Add your description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "rta_phuongnguyen", email = "phuongnguyen@rtanalytics.vn" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.11"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"fastapi",
|
|
12
|
+
"uvicorn",
|
|
13
|
+
"realtimex-agent-flows-mcp-server",
|
|
14
|
+
"dotenv",
|
|
15
|
+
"realtimex-agent-flows-builder",
|
|
16
|
+
"realtimex-agent-a2a-agent",
|
|
17
|
+
"arize-phoenix-otel",
|
|
18
|
+
"openinference-instrumentation-langchain",
|
|
19
|
+
"openinference-instrumentation-mcp",
|
|
20
|
+
"litellm==1.77.1"
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
# [tool.uv.sources]
|
|
24
|
+
# agent-flows-mcp-server = { git = "https://oauth2:5yTHSE9k34jbWgzXmsxQ@rtgit.rta.vn/rtlab/rtwebteam/mcp-servers/realtimex-ai-agent-flows", branch = "main" }
|
|
25
|
+
# agent-flows-builder = { git = "https://oauth2:5yTHSE9k34jbWgzXmsxQ@rtgit.rta.vn/rtlab/rtwebteam/realtimex-agent-flows-builder", branch = "main" }
|
|
26
|
+
# realtimex-agent-a2a-agent = { git = "https://oauth2:5yTHSE9k34jbWgzXmsxQ@rtgit.rta.vn/rtlab/rtwebteam/realtimex-agent-a2a-agent", branch = "main" }
|
|
27
|
+
# realtimex-agent-a2a-agent = { path = "/Users/phuongnguyen/Documents/projects/realtimex-agent-a2a-agent" }
|
|
28
|
+
|
|
29
|
+
[project.scripts]
|
|
30
|
+
realtimex-services-api = "realtimex_services_api.cli:main"
|
|
31
|
+
|
|
32
|
+
[build-system]
|
|
33
|
+
requires = ["uv_build>=0.8.2,<0.9.0"]
|
|
34
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CLI entry point for RealTimeX Services API
|
|
3
|
+
|
|
4
|
+
Provides command-line interface for running the FastAPI application
|
|
5
|
+
using uvicorn server with production-ready configuration.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import uvicorn
|
|
9
|
+
|
|
10
|
+
from .main import app
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main() -> None:
|
|
14
|
+
"""Main entry point for the CLI application."""
|
|
15
|
+
uvicorn.run(app, host="0.0.0.0", port=8004, reload=False, workers=1)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""
|
|
2
|
+
RealTimeX Services API - Main FastAPI Application
|
|
3
|
+
|
|
4
|
+
Production-ready FastAPI application providing commonly used services
|
|
5
|
+
in a maintainable, modular structure.
|
|
6
|
+
"""
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from fastapi import FastAPI
|
|
10
|
+
|
|
11
|
+
from .modules.a2a_agents import a2a_agents_router
|
|
12
|
+
from .modules.agent_flows import agent_flows_router
|
|
13
|
+
from .modules.python_interpreter import python_interpreter_router
|
|
14
|
+
from .telemetry import initialize_tracing
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# Configure Phoenix tracing once for the application process
|
|
18
|
+
initialize_tracing()
|
|
19
|
+
|
|
20
|
+
# Initialize FastAPI application
|
|
21
|
+
app = FastAPI(
|
|
22
|
+
title="RealTimeX Services API",
|
|
23
|
+
description="Production-ready API providing commonly used services",
|
|
24
|
+
version="0.1.0",
|
|
25
|
+
docs_url="/docs",
|
|
26
|
+
redoc_url="/redoc",
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Include routers with appropriate prefixes
|
|
30
|
+
app.include_router(agent_flows_router, prefix="/agent-flows")
|
|
31
|
+
app.include_router(a2a_agents_router, prefix="/a2a-agents")
|
|
32
|
+
app.include_router(python_interpreter_router, prefix="/python-interpreter")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@app.get("/health")
|
|
36
|
+
async def health_check():
|
|
37
|
+
"""Health check endpoint for monitoring and load balancers."""
|
|
38
|
+
return {"status": "healthy", "service": "realtimex-services-api"}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@app.get("/")
|
|
42
|
+
async def root():
|
|
43
|
+
"""Root endpoint with basic service information."""
|
|
44
|
+
return {
|
|
45
|
+
"service": "RealTimeX Services API",
|
|
46
|
+
"version": "0.1.0",
|
|
47
|
+
"docs": "/docs",
|
|
48
|
+
"health": "/health",
|
|
49
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Agent Flows Module
|
|
3
|
+
|
|
4
|
+
Provides Agent Flows testing, validation, and streaming functionality.
|
|
5
|
+
Contains API endpoints, business logic, schemas, and utilities for agent flows.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .api import a2a_agents_router
|
|
9
|
+
|
|
10
|
+
__all__ = ["a2a_agents_router"]
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""A2A Agents API Router."""
|
|
2
|
+
|
|
3
|
+
import traceback
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from fastapi import APIRouter, Body, HTTPException, Request
|
|
7
|
+
from fastapi.responses import JSONResponse
|
|
8
|
+
from openinference.instrumentation import using_metadata
|
|
9
|
+
from realtimex_agent_a2a_agent import RealTimeXAgent
|
|
10
|
+
|
|
11
|
+
# Initialize router with tags for OpenAPI documentation
|
|
12
|
+
a2a_agents_router = APIRouter(tags=["a2a-agents"])
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _create_error_response(
|
|
16
|
+
status_code: int, error_code: str, message: str, details: dict = None
|
|
17
|
+
) -> JSONResponse:
|
|
18
|
+
"""Create standardized error response."""
|
|
19
|
+
content = {
|
|
20
|
+
"success": False,
|
|
21
|
+
"error": {
|
|
22
|
+
"code": error_code,
|
|
23
|
+
"message": message,
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
if details:
|
|
27
|
+
content["error"]["details"] = details
|
|
28
|
+
|
|
29
|
+
return JSONResponse(status_code=status_code, content=content)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@a2a_agents_router.post("/sessions")
|
|
33
|
+
async def create_a2a_session(request: Request, body: Any = Body(None)) -> JSONResponse:
|
|
34
|
+
"""
|
|
35
|
+
Create A2A session
|
|
36
|
+
"""
|
|
37
|
+
try:
|
|
38
|
+
payload = body["payload"]
|
|
39
|
+
a2a_port = body["a2a_port"]
|
|
40
|
+
execution_id = body["execution_id"]
|
|
41
|
+
|
|
42
|
+
system_prompt = None
|
|
43
|
+
agent_framework = None
|
|
44
|
+
agent_description = None
|
|
45
|
+
default_model = None
|
|
46
|
+
provider_name = None
|
|
47
|
+
llm_setting = None
|
|
48
|
+
|
|
49
|
+
execution_id = payload["session_id"]
|
|
50
|
+
agent_id = payload["agent_id"]
|
|
51
|
+
agent_data = payload["agent_data"]
|
|
52
|
+
user_id = payload["user_id"]
|
|
53
|
+
workspace_slug = payload["workspace_slug"]
|
|
54
|
+
thread_id = payload["thread_id"]
|
|
55
|
+
knowledges = payload["knowledges"]
|
|
56
|
+
memory_id = payload["memory_id"]
|
|
57
|
+
memory_path = payload["memory_path"]
|
|
58
|
+
message = payload["query"]
|
|
59
|
+
messages = payload["messages"]
|
|
60
|
+
aci_linked_account_owner_id = payload["aci_linked_account_owner_id"]
|
|
61
|
+
aci_agent_first_api_key = payload["aci_api_key"]
|
|
62
|
+
realtimex_access_token = payload["realtimex_access_token"]
|
|
63
|
+
|
|
64
|
+
if "agent_description" in payload:
|
|
65
|
+
agent_description = payload["agent_description"]
|
|
66
|
+
if "agent_framework" in payload:
|
|
67
|
+
agent_framework = payload["agent_framework"]
|
|
68
|
+
if "system_prompt" in payload:
|
|
69
|
+
system_prompt = payload["system_prompt"]
|
|
70
|
+
if "llm_setting" in payload:
|
|
71
|
+
llm_setting = payload["llm_setting"]
|
|
72
|
+
|
|
73
|
+
default_openai_base_url = payload["litellm_api_base"]
|
|
74
|
+
default_openai_api_key = payload["litellm_api_key"]
|
|
75
|
+
|
|
76
|
+
trace_metadata = {
|
|
77
|
+
"realtimex_user_id": user_id,
|
|
78
|
+
"workspace_slug": workspace_slug,
|
|
79
|
+
"thread_id": thread_id,
|
|
80
|
+
"session_id": execution_id,
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
with using_metadata(trace_metadata):
|
|
84
|
+
|
|
85
|
+
# Load MCP tools
|
|
86
|
+
|
|
87
|
+
# Create agent
|
|
88
|
+
agent = RealTimeXAgent(current_session_id=execution_id)
|
|
89
|
+
|
|
90
|
+
await agent.load_default_agent(agent_id, agent_data, payload)
|
|
91
|
+
|
|
92
|
+
server_url = await agent.serve_as_a2a(a2a_serving_config={"port":a2a_port,"stream_tool_usage":True})
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
return {"server_url": server_url}
|
|
96
|
+
|
|
97
|
+
except HTTPException as e:
|
|
98
|
+
if e.status_code == 400:
|
|
99
|
+
return _create_error_response(400, "INVALID_INPUT", e.detail)
|
|
100
|
+
elif e.status_code == 404:
|
|
101
|
+
return _create_error_response(404, "USER_NOT_FOUND", e.detail)
|
|
102
|
+
else:
|
|
103
|
+
return _create_error_response(e.status_code, "REQUEST_ERROR", e.detail)
|
|
104
|
+
except Exception as e:
|
|
105
|
+
print(traceback.format_exc())
|
|
106
|
+
return _create_error_response(500, "INTERNAL_ERROR", str(e))
|
|
107
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Agent Flows Module
|
|
3
|
+
|
|
4
|
+
Provides Agent Flows testing, validation, and streaming functionality.
|
|
5
|
+
Contains API endpoints, business logic, schemas, and utilities for agent flows.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .api import agent_flows_router
|
|
9
|
+
|
|
10
|
+
__all__ = ["agent_flows_router"]
|