Skip to content

Commit a349d16

Browse files
authored
Merge pull request #574 from jupyter-naas/566-auto-publish-remote-agents-in-workspace
feat: Working on agents auto publish
2 parents 6107b38 + aa1c19f commit a349d16

6 files changed

Lines changed: 419 additions & 56 deletions

File tree

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Auto Publish Remote Agents
2+
3+
on:
4+
workflow_run:
5+
workflows: ["ABI API"] # This matches the actual API deployment workflow name
6+
types:
7+
- completed
8+
branches: [ main ]
9+
workflow_dispatch:
10+
inputs:
11+
force_publish:
12+
description: 'Force publish all agents regardless of changes'
13+
required: false
14+
default: 'false'
15+
type: boolean
16+
17+
jobs:
18+
auto-publish:
19+
runs-on: ubuntu-latest
20+
# Only run if the API deployment was successful or if manually triggered
21+
if: github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch'
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Python
28+
uses: actions/setup-python@v4
29+
with:
30+
python-version: '3.10'
31+
32+
- name: Install uv
33+
uses: astral-sh/setup-uv@v2
34+
35+
- name: Install dependencies
36+
run: |
37+
uv sync --all-extras
38+
39+
- name: Check auto-publish configuration
40+
id: check-config
41+
run: |
42+
# Check if auto-publish is enabled and get API URL
43+
CONFIG_DATA=$(uv run python -c "
44+
import yaml
45+
with open('config.yaml', 'r') as f:
46+
config = yaml.safe_load(f)
47+
48+
config_section = config.get('config', {})
49+
auto_publish = config_section.get('auto_publish', {})
50+
space_name = config_section.get('space_name', '')
51+
52+
print('AUTO_PUBLISH_ENABLED=' + str(auto_publish.get('enabled', False)).lower())
53+
print('API_BASE_URL=https://' + space_name + '-api.default.space.naas.ai')
54+
print('SPACE_NAME=' + space_name)
55+
")
56+
57+
# Parse the output
58+
eval "$CONFIG_DATA"
59+
60+
echo "auto_publish_enabled=${AUTO_PUBLISH_ENABLED}" >> $GITHUB_OUTPUT
61+
echo "api_base_url=${API_BASE_URL}" >> $GITHUB_OUTPUT
62+
echo "space_name=${SPACE_NAME}" >> $GITHUB_OUTPUT
63+
64+
if [ "$AUTO_PUBLISH_ENABLED" = "true" ]; then
65+
echo "✅ Auto-publish is enabled in configuration"
66+
echo "🌐 API Base URL: ${API_BASE_URL}"
67+
else
68+
echo "❌ Auto-publish is disabled in configuration"
69+
fi
70+
71+
- name: Verify API accessibility
72+
if: steps.check-config.outputs.auto_publish_enabled == 'true' || github.event.inputs.force_publish == 'true'
73+
run: |
74+
API_URL="${{ steps.check-config.outputs.api_base_url }}"
75+
echo "🔍 Checking if API is accessible at: ${API_URL}"
76+
77+
# Wait for API to be ready (up to 5 minutes)
78+
for i in {1..30}; do
79+
if curl -s --connect-timeout 10 "${API_URL}/health" > /dev/null 2>&1 || \
80+
curl -s --connect-timeout 10 "${API_URL}/docs" > /dev/null 2>&1 || \
81+
curl -s --connect-timeout 10 "${API_URL}/" > /dev/null 2>&1; then
82+
echo "✅ API is accessible"
83+
break
84+
fi
85+
86+
echo "⏳ API not ready yet (attempt $i/30), waiting 10 seconds..."
87+
sleep 10
88+
89+
if [ $i -eq 30 ]; then
90+
echo "❌ API is not accessible after 5 minutes. Proceeding anyway..."
91+
echo "⚠️ Published agents may not work until API is fully deployed"
92+
fi
93+
done
94+
95+
- name: Publish remote agents
96+
if: steps.check-config.outputs.auto_publish_enabled == 'true' || github.event.inputs.force_publish == 'true'
97+
env:
98+
NAAS_API_KEY: ${{ secrets.NAAS_API_KEY }}
99+
ABI_API_KEY: ${{ secrets.ABI_API_KEY }}
100+
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
run: |
102+
echo "🚀 Starting automatic agent publishing..."
103+
uv run python scripts/publish_remote_agents.py
104+
105+
- name: Notify on success
106+
if: success() && (steps.check-config.outputs.auto_publish_enabled == 'true' || github.event.inputs.force_publish == 'true')
107+
run: |
108+
echo "✅ Remote agents successfully published to workspace!"
109+
110+
- name: Notify on failure
111+
if: failure() && (steps.check-config.outputs.auto_publish_enabled == 'true' || github.event.inputs.force_publish == 'true')
112+
run: |
113+
echo "❌ Failed to publish remote agents. Check the logs for details."
114+
exit 1
115+
116+
- name: Skip publishing
117+
if: steps.check-config.outputs.auto_publish_enabled == 'false' && github.event.inputs.force_publish != 'true'
118+
run: |
119+
echo "⏭️ Auto-publish is disabled. Skipping agent publishing."
120+
echo "To enable automatic publishing, set 'config.auto_publish.enabled: true' in config.yaml"

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ publish-remote-agents: deps
244244
@ echo "Publishing remote agents..."
245245
@ uv run python scripts/publish_remote_agents.py
246246

247+
publish-remote-agents-dry-run: deps
248+
@ echo "Dry-run: Previewing remote agent publishing..."
249+
@ uv run python scripts/publish_remote_agents.py --dry-run
250+
247251
clean:
248252
@echo "Cleaning up build artifacts..."
249253
rm -rf __pycache__ .pytest_cache build dist *.egg-info lib/.venv .venv
@@ -286,7 +290,8 @@ help:
286290
@echo " triplestore-prod-override Override the production triplestore with local data"
287291
@echo " triplestore-prod-pull Pull triplestore data from production"
288292
@echo " docs-ontology Generate ontology documentation"
289-
@echo " publish-remote-agents Publish remote agents"
293+
@echo " publish-remote-agents Publish remote agents to workspace"
294+
@echo " publish-remote-agents-dry-run Preview what agents would be published (dry-run mode)"
290295
@echo ""
291296
@echo "BUILDING:"
292297
@echo " build Build the Docker image (alias for build.linux.x86_64)"

config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
config:
22
workspace_id: "96ce7ee7-e5f5-4bca-acf9-9d5d41317f81" # Naas workspace ID
3+
auto_publish:
4+
enabled: true # Enable automatic publishing of agents to workspace
5+
exclude_agents: [] # Agents to exclude from auto-publishing (empty list means publish all enabled agents)
6+
default_agent: "Abi" # Which agent to set as default in workspace
37
github_project_repository: "jupyter-naas/abi" # Github repository name (e.g. jupyter-naas/abi)
48
github_support_repository: "jupyter-naas/abi" # Github repository name (e.g. jupyter-naas/abi)
59
github_project_id: 12 # Github project number stored in Github URL (e.g. https://github.com/jupyter-naas/abi/projects/1)

config.yaml.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
config:
22
workspace_id: # Naas workspace ID
3+
auto_publish:
4+
enabled: true # Enable automatic publishing of agents to workspace
5+
exclude_agents: [] # Agents to exclude from auto-publishing (empty list means publish all enabled agents)
6+
default_agent: "Abi" # Which agent to set as default in workspace
37
github_project_repository: # Github repository name (e.g. jupyter-naas/abi)
48
github_support_repository: # Github repository name (e.g. jupyter-naas/abi)
59
github_project_id: # Github project number stored in Github URL (e.g. https://github.com/jupyter-naas/abi/projects/1)

docs/developer_tool_chain/publish_remote_agents.md

Lines changed: 154 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
This guide explains how to publish ABI agents as remote plugins on the Naas platform. This feature is only available if you have access to the Naas platform.
44

5+
## Automatic Publishing (Recommended)
6+
7+
The system now supports automatic publishing of remote agents to your workspace. When enabled, agents will be automatically published to the specified workspace using `config.workspace_id` whenever the API is deployed.
8+
59
## Prerequisites
610

711
Before publishing remote agents, ensure you have:
@@ -32,32 +36,79 @@ Update your `config.yaml` file with the following settings:
3236
```yaml
3337
config:
3438
workspace_id: "your_naas_workspace_id"
39+
auto_publish:
40+
enabled: true # Enable automatic publishing of agents to workspace
41+
exclude_agents: [] # Agents to exclude from auto-publishing (empty list means publish all enabled agents)
42+
default_agent: "Abi" # Which agent to set as default in workspace
3543
github_project_repository: "your_github_username/your_repository_name"
3644
space_name: "your_naas_space_name"
3745
# ... other configuration options
3846
```
3947

48+
#### Auto-Publish Configuration Options
49+
50+
| Option | Description | Default | Example |
51+
|--------|-------------|---------|---------|
52+
| `enabled` | Enable/disable automatic publishing | `true` | `true` |
53+
| `exclude_agents` | List of agent names to exclude from publishing | `[]` | `["TestAgent", "DebugAgent"]` |
54+
| `default_agent` | Agent to set as default in the workspace | `"Abi"` | `"MyCustomAgent"` |
55+
4056
## How to Publish Remote Agents
4157

42-
### Method 1: Using Make Command (Recommended)
58+
### Method 1: Automatic Publishing (Recommended)
59+
60+
When `auto_publish.enabled` is set to `true` in your `config.yaml`, agents will be automatically published to your workspace after each API deployment via GitHub Actions.
4361

44-
The easiest way to publish remote agents is using the provided Make command:
62+
**Benefits:**
63+
- ✅ Simplifies deployment workflow
64+
- ✅ Ensures agents are up-to-date
65+
- ✅ Reduces manual intervention
66+
- ✅ Publishes all enabled agents automatically
67+
- ✅ Excludes only specified agents via `exclude_agents`
68+
69+
**How it works:**
70+
1. GitHub Actions workflow triggers after successful API deployment
71+
2. Checks if auto-publish is enabled in configuration
72+
3. Verifies API accessibility
73+
4. Publishes all enabled agents except those in `exclude_agents`
74+
5. Sets the `default_agent` as the workspace default
75+
76+
### Method 2: Manual Publishing with Make Command
77+
78+
You can also manually publish agents using:
4579

4680
```bash
4781
make publish-remote-agents
4882
```
49-
This command performs the following actions:
50-
1. Reads configuration settings from your environment and config files
51-
2. Publishes a predefined set of agents:
52-
- `Abi` (set as default)
53-
- `Ontology`
54-
- `Naas`
55-
- `Multi_Models`
56-
- `Support`
57-
3. Configures the published agents with appropriate settings
58-
59-
To customize which agents are published, you can modify the `agents_to_publish` list directly in the script.
60-
Use the agent name to add more agents to publish.
83+
84+
**Dry-Run Mode (Preview Changes):**
85+
To preview what agents would be published without making actual changes:
86+
87+
```bash
88+
make publish-remote-agents-dry-run
89+
```
90+
91+
Or directly:
92+
```bash
93+
uv run python scripts/publish_remote_agents.py --dry-run
94+
# Alternative flags: --dryrun, -n
95+
```
96+
97+
**Dry-run benefits:**
98+
- ✅ Preview all agents that would be published
99+
- ✅ See detailed plugin configuration data
100+
- ✅ Test configuration without API keys
101+
- ✅ Identify excluded agents
102+
- ✅ Verify API URLs and workspace settings
103+
- ✅ No actual changes made to workspace or GitHub
104+
105+
**Legacy behavior (when `auto_publish.enabled: false`):**
106+
- Publishes only specific agents: `Abi`, `Ontology`, `Naas`, `Multi_Models`, `Support`
107+
- Requires manual execution
108+
109+
**New behavior (when `auto_publish.enabled: true`):**
110+
- Publishes all enabled agents except those in `exclude_agents`
111+
- Uses configuration from `config.yaml`
61112

62113
### Method 2: Running the Script Directly
63114

@@ -97,7 +148,9 @@ agents_to_publish=["Abi", "Ontology", "Naas"]
97148
| `github_access_token` | GitHub personal access token | Yes | - |
98149
| `github_repository` | GitHub repository name (format: `username/repository`) | Yes | - |
99150
| `default_agent` | Name of the agent to set as default | No | "Abi" |
100-
| `agents_to_publish` | List of agent names to publish | No | ["Abi", "Ontology", "Naas", "Multi_Models", "Support"] |
151+
| `agents_to_publish` | List of agent names to publish (legacy mode) | No | ["Abi", "Ontology", "Naas", "Multi_Models", "Support"] |
152+
| `exclude_agents` | List of agent names to exclude from publishing | No | [] |
153+
| `auto_publish_enabled` | Enable automatic publishing mode | No | false |
101154

102155
## What the Script Does
103156

@@ -113,11 +166,16 @@ The `publish_remote_agents.py` script performs the following process:
113166
- This secret is used by the remote agents to authenticate with your ABI API
114167

115168
### 3. Agent Discovery and Processing
116-
For each agent specified in `agents_to_publish`:
117169

118-
- **Loads Agent Modules**: Dynamically loads all available ABI agent modules
170+
**Auto-publish mode (when `auto_publish.enabled: true`):**
171+
- **Loads All Agent Modules**: Dynamically loads all available ABI agent modules
172+
- **Filters by Exclusion**: Publishes all agents except those listed in `exclude_agents`
173+
- **Extracts Agent Metadata**: Gathers agent information for all valid agents
174+
175+
**Legacy mode (when `auto_publish.enabled: false`):**
176+
- **Loads Specific Agents**: Only processes agents listed in `agents_to_publish`
119177
- **Extracts Agent Metadata**: Gathers agent information including:
120-
- Name and description
178+
- Name and description
121179
- System prompt from agent configuration
122180
- Avatar URL and suggestions from the module
123181
- API route name for remote access
@@ -141,18 +199,91 @@ For each agent:
141199
- Sets the specified `default_agent` as the default plugin in the workspace
142200
- This agent will be pre-selected when users access your workspace
143201

202+
## GitHub Actions Workflow
203+
204+
The automatic publishing is handled by the `.github/workflows/auto-publish-agents.yml` workflow:
205+
206+
### Workflow Triggers
207+
- **After API Deployment**: Automatically runs after the "ABI API" workflow completes successfully
208+
- **Manual Trigger**: Can be manually triggered via GitHub Actions UI with force publish option
209+
210+
### Workflow Steps
211+
1. **Checkout Code**: Gets the latest code from the repository
212+
2. **Setup Environment**: Installs Python 3.10 and uv package manager
213+
3. **Install Dependencies**: Installs all project dependencies
214+
4. **Check Configuration**: Verifies auto-publish is enabled and gets API URL
215+
5. **Verify API Access**: Waits up to 5 minutes for the API to be accessible
216+
6. **Publish Agents**: Runs the publishing script with proper configuration
217+
7. **Notify Results**: Reports success or failure
218+
219+
### Required Secrets
220+
The workflow requires these GitHub repository secrets:
221+
- `NAAS_API_KEY`: Your Naas platform API key
222+
- `ABI_API_KEY`: Your ABI API authentication key
223+
- `GITHUB_TOKEN`: Automatically provided by GitHub Actions
224+
225+
### Workflow Configuration
226+
The workflow is configured to trigger after the "ABI API" deployment workflow:
227+
```yaml
228+
workflows: ["ABI API"] # Matches the actual API deployment workflow name
229+
```
230+
144231
## Expected Output
145232
146233
When running the script successfully, you should see output similar to:
147234
235+
**Auto-publish mode:**
148236
```
149-
==> Getting existing plugins from workspace: your_workspace_id
150-
==> Existing plugins: 5
151-
==> Updating "ABI_API_KEY" secret in Github repository: your_username/your_repo
237+
🚀 Auto-publish enabled: True
238+
🚫 Excluded agents: None
239+
⭐ Default agent: Abi
240+
🔍 Getting existing plugins from workspace: your_workspace_id
241+
==> Getting agents from module: src/core/modules/abi
152242
==> Publishing agent: Abi
153-
Plugin 'Abi' updated in workspace 'your_workspace_id'
243+
Plugin 'Abi' updated in workspace 'your_workspace_id'
154244
==> Publishing agent: Ontology
155-
Plugin 'Ontology' created in workspace 'your_workspace_id'
245+
✅ Plugin 'Ontology' created in workspace 'your_workspace_id'
246+
==> Skipping excluded agent: TestAgent
247+
...
248+
```
249+
250+
**Legacy mode:**
251+
```
252+
🚀 Auto-publish enabled: False
253+
📝 Publishing specific agents: ['Abi', 'Ontology', 'Naas', 'Multi_Models', 'Support']
254+
⭐ Default agent: Abi
255+
🔍 Getting existing plugins from workspace: your_workspace_id
256+
==> Publishing agent: Abi
257+
✅ Plugin 'Abi' updated in workspace 'your_workspace_id'
258+
...
259+
```
260+
261+
**Dry-run mode:**
262+
```
263+
🧪 DRY RUN MODE - No changes will be made
264+
==================================================
265+
🚀 Auto-publish enabled: True
266+
🚫 Excluded agents: ['TestAgent']
267+
⭐ Default agent: Abi
268+
🌐 API Base URL: https://abi-api.default.space.naas.ai
269+
🏢 Workspace ID: your_workspace_id
270+
🧪 DRY RUN MODE: No actual changes will be made
271+
🧪 [DRY RUN] Would fetch existing plugins from workspace
272+
🧪 [DRY RUN] Would update "ABI_API_KEY" secret in Github repository: your_repo
273+
==> Getting agents from module: src/core/modules/abi
274+
🧪 [DRY RUN] Would publish agent: Abi
275+
🧪 [DRY RUN] Plugin data for 'Abi':
276+
- ID: abi
277+
- Name: Abi
278+
- Type: CORE
279+
- Default: True
280+
- Remote URL: https://abi-api.default.space.naas.ai/agents/abi/stream-completion?token=dummy_abi_api_key
281+
- Avatar: https://naasai-public.s3.eu-west-3.amazonaws.com/abi-demo/ontology_ABI.png
282+
- Description: I'm Abi, your Artificial Business Intelligence assistant...
283+
- Suggestions: 4 items
284+
🧪 [DRY RUN] Would check if plugin 'abi' already exists
285+
🧪 [DRY RUN] Would create/update plugin in workspace 'your_workspace_id'
286+
🧪 [DRY RUN] Would skip excluded agent: TestAgent
156287
...
157288
```
158289

0 commit comments

Comments
 (0)