bfa-irc-a-sdk 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.
- bfa_irc_a_sdk-0.1.0/PKG-INFO +145 -0
- bfa_irc_a_sdk-0.1.0/README.md +118 -0
- bfa_irc_a_sdk-0.1.0/bfa_irc_a_sdk.egg-info/PKG-INFO +145 -0
- bfa_irc_a_sdk-0.1.0/bfa_irc_a_sdk.egg-info/SOURCES.txt +21 -0
- bfa_irc_a_sdk-0.1.0/bfa_irc_a_sdk.egg-info/dependency_links.txt +1 -0
- bfa_irc_a_sdk-0.1.0/bfa_irc_a_sdk.egg-info/requires.txt +17 -0
- bfa_irc_a_sdk-0.1.0/bfa_irc_a_sdk.egg-info/top_level.txt +1 -0
- bfa_irc_a_sdk-0.1.0/bfa_sdk/__init__.py +13 -0
- bfa_irc_a_sdk-0.1.0/bfa_sdk/config.py +45 -0
- bfa_irc_a_sdk-0.1.0/bfa_sdk/core/__init__.py +1 -0
- bfa_irc_a_sdk-0.1.0/bfa_sdk/core/agent.py +353 -0
- bfa_irc_a_sdk-0.1.0/bfa_sdk/core/gateway.py +529 -0
- bfa_irc_a_sdk-0.1.0/bfa_sdk/core/mcp.py +336 -0
- bfa_irc_a_sdk-0.1.0/bfa_sdk/router/embedder.py +110 -0
- bfa_irc_a_sdk-0.1.0/bfa_sdk/router/search.py +135 -0
- bfa_irc_a_sdk-0.1.0/pyproject.toml +43 -0
- bfa_irc_a_sdk-0.1.0/setup.cfg +4 -0
- bfa_irc_a_sdk-0.1.0/tests/test_config.py +54 -0
- bfa_irc_a_sdk-0.1.0/tests/test_core_wrappers.py +188 -0
- bfa_irc_a_sdk-0.1.0/tests/test_embedder.py +97 -0
- bfa_irc_a_sdk-0.1.0/tests/test_gateway.py +403 -0
- bfa_irc_a_sdk-0.1.0/tests/test_irca_security.py +1091 -0
- bfa_irc_a_sdk-0.1.0/tests/test_router.py +109 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bfa-irc-a-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A generic Backend for Agents (BFA) SDK with FAISS semantic routing.
|
|
5
|
+
Author: Sandro Garcia
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: fastapi
|
|
12
|
+
Requires-Dist: uvicorn
|
|
13
|
+
Requires-Dist: httpx
|
|
14
|
+
Requires-Dist: python-dotenv
|
|
15
|
+
Requires-Dist: a2a-sdk
|
|
16
|
+
Requires-Dist: numpy
|
|
17
|
+
Requires-Dist: faiss-cpu
|
|
18
|
+
Requires-Dist: pydantic
|
|
19
|
+
Requires-Dist: fastmcp
|
|
20
|
+
Requires-Dist: pyyaml
|
|
21
|
+
Requires-Dist: mangum
|
|
22
|
+
Requires-Dist: openai
|
|
23
|
+
Requires-Dist: pyjwt
|
|
24
|
+
Requires-Dist: cryptography
|
|
25
|
+
Provides-Extra: local
|
|
26
|
+
Requires-Dist: sentence-transformers; extra == "local"
|
|
27
|
+
|
|
28
|
+
# Backend for Agents SDK (BFA) & IRC-A Protocol
|
|
29
|
+
|
|
30
|
+
A generic and opinionated framework and SDK to implement the **BFA (Backend for Agents)** pattern and the **IRC-A (Internet Relay Chat for Agents)** protocol, featuring native support for **FAISS-based Semantic Routing (vector search)**, asymmetric zero-trust security boundaries, and standard abstractions for A2A Agents and MCP Servers.
|
|
31
|
+
|
|
32
|
+
Read the official protocol specification:
|
|
33
|
+
👉 **[IRC-A Protocol Whitepaper (v1.0.0)](IRC-A_Whitepaper.md)** - *Decentralized Agent Networks, Semantic Capability Routing, and Secure-by-Design Software Architecture.*
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Multilingual Documentation
|
|
38
|
+
* [Português (Portuguese)](README.pt.md)
|
|
39
|
+
* [Español (Spanish)](README.es.md)
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## BFA / IRC-A Protocol Architecture
|
|
44
|
+
|
|
45
|
+
The BFA Gateway acts as a semantic middleware and registry broker layer between consumers (e.g., messaging UIs, chat systems) and specialized agents/tools.
|
|
46
|
+
|
|
47
|
+
```mermaid
|
|
48
|
+
graph TD
|
|
49
|
+
Consumer["Consumer UI / Whatsapp / WebApp"] -->|1. Resolve Query| BFA[BFA Gateway]
|
|
50
|
+
|
|
51
|
+
subgraph BFA_Gateway ["BFA Gateway (Backend for Agents)"]
|
|
52
|
+
Router[Semantic Router] -->|2. Search Embeddings| FAISS[FAISS Vector Store]
|
|
53
|
+
Registry[Registry] -->|Load metadata| Router
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
BFA -->|3. Route & Invoke| Agent1["Cuentas Agent (A2A)"]
|
|
57
|
+
BFA -->|3. Route & Invoke| Agent2["Tarjetas Agent (A2A)"]
|
|
58
|
+
BFA -->|4. Execute Tool| MCP1["MDBank MCP (FastMCP)"]
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Key Features
|
|
64
|
+
|
|
65
|
+
1. **FAISS-Based Semantic Routing:** Instead of matching exact keywords (like BM25), the BFA Gateway indexes the descriptions, tags, and examples of agents and tools in a local FAISS vector index. This resolves queries to matching functions even when synonyms are used (e.g., matching *"plastic"* to *"credit card"*).
|
|
66
|
+
2. **`BFAAgent` Abstraction:** Simplifies building A2A agents using the `a2a-sdk` and Starlette. Forces standard metadata declarations (`tags`, `examples`, `description`) required for semantic indexing.
|
|
67
|
+
3. **`BFAMCP` Abstraction:** Wraps and extends `FastMCP` servers. Automatically exposes a standardized `/tools` endpoint returning input schemas, descriptions, and custom tags/examples for discovery.
|
|
68
|
+
4. **Secure-by-Design IRC-A Security (Roadmap):** Employs asymmetric challenge-response registration handshakes, logical channel masking (via container-level `IRCA_CHANNELS` env variables) to segregate vector search spaces, and Ephemeral DET (Delegated Execution Tokens) to enable direct decentralized P2P invocation without gateway bottlenecks.
|
|
69
|
+
5. **Serverless (AWS Lambda) Ready:** Includes a built-in **Mangum** adapter in the Gateway. Combined with the cloud-based `OpenAIEmbedder`, the BFA Gateway runs serverless on demand with zero cold-starts.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Configuring Embedding Providers & Chunking
|
|
74
|
+
|
|
75
|
+
The BFA Gateway uses semantic embeddings to index agent/tool metadata in FAISS. You can choose between local models, cloud APIs, or offline mock routing via environment variables:
|
|
76
|
+
|
|
77
|
+
| Mode / Provider | Environment Variables | Dependencies | Description |
|
|
78
|
+
|---|---|---|---|
|
|
79
|
+
| **Local Real (Default)** | None | `bfa-sdk[local]` | Uses `sentence-transformers` locally. Recommended for Python <= 3.12 environments. |
|
|
80
|
+
| **OpenAI (Cloud)** | `BFA_USE_OPENAI_EMBEDDINGS=true`, `OPENAI_API_KEY="..."` | `openai` | Queries OpenAI's `text-embedding-3-small` endpoint. Perfect for serverless/Lambda environments. |
|
|
81
|
+
| **Offline Mock (Feature Hashing)** | `BFA_USE_MOCK_EMBEDDINGS=true` | None | Uses a stable MD5 feature hashing trick to route queries based on keywords. Zero dependencies, fast, and local. |
|
|
82
|
+
|
|
83
|
+
> [!NOTE]
|
|
84
|
+
> **Why is there no Chunking in the Gateway?**
|
|
85
|
+
> The BFA Gateway is a semantic router of services, not a document retrieval engine (RAG). It indexes short microservice metadata cards (names, descriptions, tags, examples) which fit completely within embedding token limits.
|
|
86
|
+
> If you need to perform **Document Chunking** (RAG over PDFs/manuals), it should be implemented **inside the respective A2A Agent's internal database/logic**, keeping the Gateway lightweight and decoupled from document storage.
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Installation
|
|
91
|
+
|
|
92
|
+
You can install the BFA SDK directly from GitHub using `pip`:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# Install the development version from the main branch
|
|
96
|
+
pip install git+https://github.com/SandroG1977/bfa-sdk.git
|
|
97
|
+
|
|
98
|
+
# Or install a specific version with the secure IRC-A protocol support
|
|
99
|
+
pip install git+https://github.com/SandroG1977/bfa-sdk.git@feature/docstrings-init
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Running the Demo
|
|
105
|
+
|
|
106
|
+
### 2. Run the MDBank Demo
|
|
107
|
+
The demo launches three mock servers in the background:
|
|
108
|
+
1. A mock MDBank MCP server (`examples/mock_mdbank_mcp.py`) on port `8001`.
|
|
109
|
+
2. A mock Cuentas A2A Agent (`examples/mock_cuentas_agent.py`) on port `8002`.
|
|
110
|
+
3. A mock Tarjetas A2A Agent (`examples/mock_tarjetas_agent.py`) on port `8003`.
|
|
111
|
+
4. The BFA Gateway on port `8000`, running dynamic discovery and performing test queries.
|
|
112
|
+
|
|
113
|
+
To run:
|
|
114
|
+
```bash
|
|
115
|
+
python examples/run_demo.py
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 3. Run the UI Dashboard (IRC-A Central Hub)
|
|
119
|
+
We have included a React-based UI Dashboard under `examples/frontend` to visually monitor the active agents/tools registry, register new microservices dynamically (plug-and-play), and chat with the routed banking agents:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
# Navigate to the frontend folder
|
|
123
|
+
cd examples/frontend
|
|
124
|
+
|
|
125
|
+
# Install dependencies
|
|
126
|
+
npm install
|
|
127
|
+
|
|
128
|
+
# Start the development server
|
|
129
|
+
npm start
|
|
130
|
+
```
|
|
131
|
+
Open `http://localhost:3000` to interact with your local agent hub in real-time.
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Credits & Acknowledgements
|
|
137
|
+
|
|
138
|
+
This SDK is a community-driven implementation and expansion of the **BFA (Backend for Agents)** architectural pattern originally designed and documented by **Michael Douglas Barbosa Araujo** (Staff AI Architect).
|
|
139
|
+
|
|
140
|
+
You can read his original article introducing the pattern here:
|
|
141
|
+
👉 [O padrão Back-end para Agentes (BFA) - Medium](https://medium.com/@mdbaraujo/o-padr%C3%A3o-back-end-para-agentes-bfa-a53c1c6d87fb)
|
|
142
|
+
|
|
143
|
+
The goal of this project is to provide a standardized, packaged SDK extending his original concept with semantic vector routing (FAISS) and unified base adapters. All credit for the underlying protocol and architectural vision belongs to him.
|
|
144
|
+
|
|
145
|
+
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Backend for Agents SDK (BFA) & IRC-A Protocol
|
|
2
|
+
|
|
3
|
+
A generic and opinionated framework and SDK to implement the **BFA (Backend for Agents)** pattern and the **IRC-A (Internet Relay Chat for Agents)** protocol, featuring native support for **FAISS-based Semantic Routing (vector search)**, asymmetric zero-trust security boundaries, and standard abstractions for A2A Agents and MCP Servers.
|
|
4
|
+
|
|
5
|
+
Read the official protocol specification:
|
|
6
|
+
👉 **[IRC-A Protocol Whitepaper (v1.0.0)](IRC-A_Whitepaper.md)** - *Decentralized Agent Networks, Semantic Capability Routing, and Secure-by-Design Software Architecture.*
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Multilingual Documentation
|
|
11
|
+
* [Português (Portuguese)](README.pt.md)
|
|
12
|
+
* [Español (Spanish)](README.es.md)
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## BFA / IRC-A Protocol Architecture
|
|
17
|
+
|
|
18
|
+
The BFA Gateway acts as a semantic middleware and registry broker layer between consumers (e.g., messaging UIs, chat systems) and specialized agents/tools.
|
|
19
|
+
|
|
20
|
+
```mermaid
|
|
21
|
+
graph TD
|
|
22
|
+
Consumer["Consumer UI / Whatsapp / WebApp"] -->|1. Resolve Query| BFA[BFA Gateway]
|
|
23
|
+
|
|
24
|
+
subgraph BFA_Gateway ["BFA Gateway (Backend for Agents)"]
|
|
25
|
+
Router[Semantic Router] -->|2. Search Embeddings| FAISS[FAISS Vector Store]
|
|
26
|
+
Registry[Registry] -->|Load metadata| Router
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
BFA -->|3. Route & Invoke| Agent1["Cuentas Agent (A2A)"]
|
|
30
|
+
BFA -->|3. Route & Invoke| Agent2["Tarjetas Agent (A2A)"]
|
|
31
|
+
BFA -->|4. Execute Tool| MCP1["MDBank MCP (FastMCP)"]
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Key Features
|
|
37
|
+
|
|
38
|
+
1. **FAISS-Based Semantic Routing:** Instead of matching exact keywords (like BM25), the BFA Gateway indexes the descriptions, tags, and examples of agents and tools in a local FAISS vector index. This resolves queries to matching functions even when synonyms are used (e.g., matching *"plastic"* to *"credit card"*).
|
|
39
|
+
2. **`BFAAgent` Abstraction:** Simplifies building A2A agents using the `a2a-sdk` and Starlette. Forces standard metadata declarations (`tags`, `examples`, `description`) required for semantic indexing.
|
|
40
|
+
3. **`BFAMCP` Abstraction:** Wraps and extends `FastMCP` servers. Automatically exposes a standardized `/tools` endpoint returning input schemas, descriptions, and custom tags/examples for discovery.
|
|
41
|
+
4. **Secure-by-Design IRC-A Security (Roadmap):** Employs asymmetric challenge-response registration handshakes, logical channel masking (via container-level `IRCA_CHANNELS` env variables) to segregate vector search spaces, and Ephemeral DET (Delegated Execution Tokens) to enable direct decentralized P2P invocation without gateway bottlenecks.
|
|
42
|
+
5. **Serverless (AWS Lambda) Ready:** Includes a built-in **Mangum** adapter in the Gateway. Combined with the cloud-based `OpenAIEmbedder`, the BFA Gateway runs serverless on demand with zero cold-starts.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Configuring Embedding Providers & Chunking
|
|
47
|
+
|
|
48
|
+
The BFA Gateway uses semantic embeddings to index agent/tool metadata in FAISS. You can choose between local models, cloud APIs, or offline mock routing via environment variables:
|
|
49
|
+
|
|
50
|
+
| Mode / Provider | Environment Variables | Dependencies | Description |
|
|
51
|
+
|---|---|---|---|
|
|
52
|
+
| **Local Real (Default)** | None | `bfa-sdk[local]` | Uses `sentence-transformers` locally. Recommended for Python <= 3.12 environments. |
|
|
53
|
+
| **OpenAI (Cloud)** | `BFA_USE_OPENAI_EMBEDDINGS=true`, `OPENAI_API_KEY="..."` | `openai` | Queries OpenAI's `text-embedding-3-small` endpoint. Perfect for serverless/Lambda environments. |
|
|
54
|
+
| **Offline Mock (Feature Hashing)** | `BFA_USE_MOCK_EMBEDDINGS=true` | None | Uses a stable MD5 feature hashing trick to route queries based on keywords. Zero dependencies, fast, and local. |
|
|
55
|
+
|
|
56
|
+
> [!NOTE]
|
|
57
|
+
> **Why is there no Chunking in the Gateway?**
|
|
58
|
+
> The BFA Gateway is a semantic router of services, not a document retrieval engine (RAG). It indexes short microservice metadata cards (names, descriptions, tags, examples) which fit completely within embedding token limits.
|
|
59
|
+
> If you need to perform **Document Chunking** (RAG over PDFs/manuals), it should be implemented **inside the respective A2A Agent's internal database/logic**, keeping the Gateway lightweight and decoupled from document storage.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Installation
|
|
64
|
+
|
|
65
|
+
You can install the BFA SDK directly from GitHub using `pip`:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
# Install the development version from the main branch
|
|
69
|
+
pip install git+https://github.com/SandroG1977/bfa-sdk.git
|
|
70
|
+
|
|
71
|
+
# Or install a specific version with the secure IRC-A protocol support
|
|
72
|
+
pip install git+https://github.com/SandroG1977/bfa-sdk.git@feature/docstrings-init
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Running the Demo
|
|
78
|
+
|
|
79
|
+
### 2. Run the MDBank Demo
|
|
80
|
+
The demo launches three mock servers in the background:
|
|
81
|
+
1. A mock MDBank MCP server (`examples/mock_mdbank_mcp.py`) on port `8001`.
|
|
82
|
+
2. A mock Cuentas A2A Agent (`examples/mock_cuentas_agent.py`) on port `8002`.
|
|
83
|
+
3. A mock Tarjetas A2A Agent (`examples/mock_tarjetas_agent.py`) on port `8003`.
|
|
84
|
+
4. The BFA Gateway on port `8000`, running dynamic discovery and performing test queries.
|
|
85
|
+
|
|
86
|
+
To run:
|
|
87
|
+
```bash
|
|
88
|
+
python examples/run_demo.py
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### 3. Run the UI Dashboard (IRC-A Central Hub)
|
|
92
|
+
We have included a React-based UI Dashboard under `examples/frontend` to visually monitor the active agents/tools registry, register new microservices dynamically (plug-and-play), and chat with the routed banking agents:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# Navigate to the frontend folder
|
|
96
|
+
cd examples/frontend
|
|
97
|
+
|
|
98
|
+
# Install dependencies
|
|
99
|
+
npm install
|
|
100
|
+
|
|
101
|
+
# Start the development server
|
|
102
|
+
npm start
|
|
103
|
+
```
|
|
104
|
+
Open `http://localhost:3000` to interact with your local agent hub in real-time.
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Credits & Acknowledgements
|
|
110
|
+
|
|
111
|
+
This SDK is a community-driven implementation and expansion of the **BFA (Backend for Agents)** architectural pattern originally designed and documented by **Michael Douglas Barbosa Araujo** (Staff AI Architect).
|
|
112
|
+
|
|
113
|
+
You can read his original article introducing the pattern here:
|
|
114
|
+
👉 [O padrão Back-end para Agentes (BFA) - Medium](https://medium.com/@mdbaraujo/o-padr%C3%A3o-back-end-para-agentes-bfa-a53c1c6d87fb)
|
|
115
|
+
|
|
116
|
+
The goal of this project is to provide a standardized, packaged SDK extending his original concept with semantic vector routing (FAISS) and unified base adapters. All credit for the underlying protocol and architectural vision belongs to him.
|
|
117
|
+
|
|
118
|
+
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bfa-irc-a-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A generic Backend for Agents (BFA) SDK with FAISS semantic routing.
|
|
5
|
+
Author: Sandro Garcia
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: fastapi
|
|
12
|
+
Requires-Dist: uvicorn
|
|
13
|
+
Requires-Dist: httpx
|
|
14
|
+
Requires-Dist: python-dotenv
|
|
15
|
+
Requires-Dist: a2a-sdk
|
|
16
|
+
Requires-Dist: numpy
|
|
17
|
+
Requires-Dist: faiss-cpu
|
|
18
|
+
Requires-Dist: pydantic
|
|
19
|
+
Requires-Dist: fastmcp
|
|
20
|
+
Requires-Dist: pyyaml
|
|
21
|
+
Requires-Dist: mangum
|
|
22
|
+
Requires-Dist: openai
|
|
23
|
+
Requires-Dist: pyjwt
|
|
24
|
+
Requires-Dist: cryptography
|
|
25
|
+
Provides-Extra: local
|
|
26
|
+
Requires-Dist: sentence-transformers; extra == "local"
|
|
27
|
+
|
|
28
|
+
# Backend for Agents SDK (BFA) & IRC-A Protocol
|
|
29
|
+
|
|
30
|
+
A generic and opinionated framework and SDK to implement the **BFA (Backend for Agents)** pattern and the **IRC-A (Internet Relay Chat for Agents)** protocol, featuring native support for **FAISS-based Semantic Routing (vector search)**, asymmetric zero-trust security boundaries, and standard abstractions for A2A Agents and MCP Servers.
|
|
31
|
+
|
|
32
|
+
Read the official protocol specification:
|
|
33
|
+
👉 **[IRC-A Protocol Whitepaper (v1.0.0)](IRC-A_Whitepaper.md)** - *Decentralized Agent Networks, Semantic Capability Routing, and Secure-by-Design Software Architecture.*
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Multilingual Documentation
|
|
38
|
+
* [Português (Portuguese)](README.pt.md)
|
|
39
|
+
* [Español (Spanish)](README.es.md)
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## BFA / IRC-A Protocol Architecture
|
|
44
|
+
|
|
45
|
+
The BFA Gateway acts as a semantic middleware and registry broker layer between consumers (e.g., messaging UIs, chat systems) and specialized agents/tools.
|
|
46
|
+
|
|
47
|
+
```mermaid
|
|
48
|
+
graph TD
|
|
49
|
+
Consumer["Consumer UI / Whatsapp / WebApp"] -->|1. Resolve Query| BFA[BFA Gateway]
|
|
50
|
+
|
|
51
|
+
subgraph BFA_Gateway ["BFA Gateway (Backend for Agents)"]
|
|
52
|
+
Router[Semantic Router] -->|2. Search Embeddings| FAISS[FAISS Vector Store]
|
|
53
|
+
Registry[Registry] -->|Load metadata| Router
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
BFA -->|3. Route & Invoke| Agent1["Cuentas Agent (A2A)"]
|
|
57
|
+
BFA -->|3. Route & Invoke| Agent2["Tarjetas Agent (A2A)"]
|
|
58
|
+
BFA -->|4. Execute Tool| MCP1["MDBank MCP (FastMCP)"]
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Key Features
|
|
64
|
+
|
|
65
|
+
1. **FAISS-Based Semantic Routing:** Instead of matching exact keywords (like BM25), the BFA Gateway indexes the descriptions, tags, and examples of agents and tools in a local FAISS vector index. This resolves queries to matching functions even when synonyms are used (e.g., matching *"plastic"* to *"credit card"*).
|
|
66
|
+
2. **`BFAAgent` Abstraction:** Simplifies building A2A agents using the `a2a-sdk` and Starlette. Forces standard metadata declarations (`tags`, `examples`, `description`) required for semantic indexing.
|
|
67
|
+
3. **`BFAMCP` Abstraction:** Wraps and extends `FastMCP` servers. Automatically exposes a standardized `/tools` endpoint returning input schemas, descriptions, and custom tags/examples for discovery.
|
|
68
|
+
4. **Secure-by-Design IRC-A Security (Roadmap):** Employs asymmetric challenge-response registration handshakes, logical channel masking (via container-level `IRCA_CHANNELS` env variables) to segregate vector search spaces, and Ephemeral DET (Delegated Execution Tokens) to enable direct decentralized P2P invocation without gateway bottlenecks.
|
|
69
|
+
5. **Serverless (AWS Lambda) Ready:** Includes a built-in **Mangum** adapter in the Gateway. Combined with the cloud-based `OpenAIEmbedder`, the BFA Gateway runs serverless on demand with zero cold-starts.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Configuring Embedding Providers & Chunking
|
|
74
|
+
|
|
75
|
+
The BFA Gateway uses semantic embeddings to index agent/tool metadata in FAISS. You can choose between local models, cloud APIs, or offline mock routing via environment variables:
|
|
76
|
+
|
|
77
|
+
| Mode / Provider | Environment Variables | Dependencies | Description |
|
|
78
|
+
|---|---|---|---|
|
|
79
|
+
| **Local Real (Default)** | None | `bfa-sdk[local]` | Uses `sentence-transformers` locally. Recommended for Python <= 3.12 environments. |
|
|
80
|
+
| **OpenAI (Cloud)** | `BFA_USE_OPENAI_EMBEDDINGS=true`, `OPENAI_API_KEY="..."` | `openai` | Queries OpenAI's `text-embedding-3-small` endpoint. Perfect for serverless/Lambda environments. |
|
|
81
|
+
| **Offline Mock (Feature Hashing)** | `BFA_USE_MOCK_EMBEDDINGS=true` | None | Uses a stable MD5 feature hashing trick to route queries based on keywords. Zero dependencies, fast, and local. |
|
|
82
|
+
|
|
83
|
+
> [!NOTE]
|
|
84
|
+
> **Why is there no Chunking in the Gateway?**
|
|
85
|
+
> The BFA Gateway is a semantic router of services, not a document retrieval engine (RAG). It indexes short microservice metadata cards (names, descriptions, tags, examples) which fit completely within embedding token limits.
|
|
86
|
+
> If you need to perform **Document Chunking** (RAG over PDFs/manuals), it should be implemented **inside the respective A2A Agent's internal database/logic**, keeping the Gateway lightweight and decoupled from document storage.
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Installation
|
|
91
|
+
|
|
92
|
+
You can install the BFA SDK directly from GitHub using `pip`:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# Install the development version from the main branch
|
|
96
|
+
pip install git+https://github.com/SandroG1977/bfa-sdk.git
|
|
97
|
+
|
|
98
|
+
# Or install a specific version with the secure IRC-A protocol support
|
|
99
|
+
pip install git+https://github.com/SandroG1977/bfa-sdk.git@feature/docstrings-init
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Running the Demo
|
|
105
|
+
|
|
106
|
+
### 2. Run the MDBank Demo
|
|
107
|
+
The demo launches three mock servers in the background:
|
|
108
|
+
1. A mock MDBank MCP server (`examples/mock_mdbank_mcp.py`) on port `8001`.
|
|
109
|
+
2. A mock Cuentas A2A Agent (`examples/mock_cuentas_agent.py`) on port `8002`.
|
|
110
|
+
3. A mock Tarjetas A2A Agent (`examples/mock_tarjetas_agent.py`) on port `8003`.
|
|
111
|
+
4. The BFA Gateway on port `8000`, running dynamic discovery and performing test queries.
|
|
112
|
+
|
|
113
|
+
To run:
|
|
114
|
+
```bash
|
|
115
|
+
python examples/run_demo.py
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 3. Run the UI Dashboard (IRC-A Central Hub)
|
|
119
|
+
We have included a React-based UI Dashboard under `examples/frontend` to visually monitor the active agents/tools registry, register new microservices dynamically (plug-and-play), and chat with the routed banking agents:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
# Navigate to the frontend folder
|
|
123
|
+
cd examples/frontend
|
|
124
|
+
|
|
125
|
+
# Install dependencies
|
|
126
|
+
npm install
|
|
127
|
+
|
|
128
|
+
# Start the development server
|
|
129
|
+
npm start
|
|
130
|
+
```
|
|
131
|
+
Open `http://localhost:3000` to interact with your local agent hub in real-time.
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Credits & Acknowledgements
|
|
137
|
+
|
|
138
|
+
This SDK is a community-driven implementation and expansion of the **BFA (Backend for Agents)** architectural pattern originally designed and documented by **Michael Douglas Barbosa Araujo** (Staff AI Architect).
|
|
139
|
+
|
|
140
|
+
You can read his original article introducing the pattern here:
|
|
141
|
+
👉 [O padrão Back-end para Agentes (BFA) - Medium](https://medium.com/@mdbaraujo/o-padr%C3%A3o-back-end-para-agentes-bfa-a53c1c6d87fb)
|
|
142
|
+
|
|
143
|
+
The goal of this project is to provide a standardized, packaged SDK extending his original concept with semantic vector routing (FAISS) and unified base adapters. All credit for the underlying protocol and architectural vision belongs to him.
|
|
144
|
+
|
|
145
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
bfa_irc_a_sdk.egg-info/PKG-INFO
|
|
4
|
+
bfa_irc_a_sdk.egg-info/SOURCES.txt
|
|
5
|
+
bfa_irc_a_sdk.egg-info/dependency_links.txt
|
|
6
|
+
bfa_irc_a_sdk.egg-info/requires.txt
|
|
7
|
+
bfa_irc_a_sdk.egg-info/top_level.txt
|
|
8
|
+
bfa_sdk/__init__.py
|
|
9
|
+
bfa_sdk/config.py
|
|
10
|
+
bfa_sdk/core/__init__.py
|
|
11
|
+
bfa_sdk/core/agent.py
|
|
12
|
+
bfa_sdk/core/gateway.py
|
|
13
|
+
bfa_sdk/core/mcp.py
|
|
14
|
+
bfa_sdk/router/embedder.py
|
|
15
|
+
bfa_sdk/router/search.py
|
|
16
|
+
tests/test_config.py
|
|
17
|
+
tests/test_core_wrappers.py
|
|
18
|
+
tests/test_embedder.py
|
|
19
|
+
tests/test_gateway.py
|
|
20
|
+
tests/test_irca_security.py
|
|
21
|
+
tests/test_router.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bfa_sdk
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Backend for Agents SDK (BFA)
|
|
2
|
+
# Version 0.1.0
|
|
3
|
+
"""
|
|
4
|
+
BFA SDK: A lightweight framework for Backend for Agents (BFA) architecture with FAISS semantic routing.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
from bfa_sdk.core.agent import BFAAgent
|
|
9
|
+
from bfa_sdk.core.mcp import BFAMCP
|
|
10
|
+
from bfa_sdk.core.gateway import create_gateway_app
|
|
11
|
+
from bfa_sdk.router.search import BFASemanticRouter
|
|
12
|
+
|
|
13
|
+
__all__ = ["BFAAgent", "BFAMCP", "create_gateway_app", "BFASemanticRouter"]
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import yaml
|
|
3
|
+
from typing import List, Dict, Any
|
|
4
|
+
|
|
5
|
+
class BFAConfig:
|
|
6
|
+
"""
|
|
7
|
+
Configuration helper parsing endpoints and models from environment variables
|
|
8
|
+
or a YAML configuration file.
|
|
9
|
+
"""
|
|
10
|
+
def __init__(self, config_path: str = None):
|
|
11
|
+
self.agent_endpoints: List[str] = []
|
|
12
|
+
self.mcp_endpoints: List[str] = []
|
|
13
|
+
self.embedding_model: str = "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
|
|
14
|
+
self.use_mock_embeddings: bool = False
|
|
15
|
+
self.use_openai_embeddings: bool = False
|
|
16
|
+
self.openai_api_key: str = ""
|
|
17
|
+
|
|
18
|
+
# Load from config file if provided
|
|
19
|
+
if config_path and os.path.exists(config_path):
|
|
20
|
+
self.load_from_file(config_path)
|
|
21
|
+
else:
|
|
22
|
+
self.load_from_env()
|
|
23
|
+
|
|
24
|
+
def load_from_file(self, path: str):
|
|
25
|
+
with open(path, "r") as f:
|
|
26
|
+
data = yaml.safe_load(f) or {}
|
|
27
|
+
self.agent_endpoints = data.get("agent_endpoints", [])
|
|
28
|
+
self.mcp_endpoints = data.get("mcp_endpoints", [])
|
|
29
|
+
self.embedding_model = data.get("embedding_model", self.embedding_model)
|
|
30
|
+
self.use_mock_embeddings = data.get("use_mock_embeddings", False)
|
|
31
|
+
self.use_openai_embeddings = data.get("use_openai_embeddings", False)
|
|
32
|
+
self.openai_api_key = data.get("openai_api_key", "")
|
|
33
|
+
|
|
34
|
+
def load_from_env(self):
|
|
35
|
+
# Parse comma-separated strings
|
|
36
|
+
agents_env = os.getenv("BFA_AGENT_ENDPOINTS", "")
|
|
37
|
+
self.agent_endpoints = [x.strip() for x in agents_env.split(",") if x.strip()]
|
|
38
|
+
|
|
39
|
+
mcps_env = os.getenv("BFA_MCP_ENDPOINTS", "")
|
|
40
|
+
self.mcp_endpoints = [x.strip() for x in mcps_env.split(",") if x.strip()]
|
|
41
|
+
|
|
42
|
+
self.embedding_model = os.getenv("BFA_EMBEDDING_MODEL", self.embedding_model)
|
|
43
|
+
self.use_mock_embeddings = os.getenv("BFA_USE_MOCK_EMBEDDINGS", "false").lower() == "true"
|
|
44
|
+
self.use_openai_embeddings = os.getenv("BFA_USE_OPENAI_EMBEDDINGS", "false").lower() == "true"
|
|
45
|
+
self.openai_api_key = os.getenv("OPENAI_API_KEY", "")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Core modules for BFA SDK
|