Spaces:
Build error
Build error
Upload 111 files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .dockerignore +7 -0
- .env +2 -0
- .gitattributes +1 -0
- .github/workflows/docker.yml +28 -0
- .github/workflows/trufflehog.yml +18 -0
- .gitignore +58 -0
- .idea/.gitignore +8 -0
- .idea/kotlinc.xml +6 -0
- .idea/material_theme_project_new.xml +13 -0
- .idea/vcs.xml +6 -0
- CONTRIBUTING.md +3 -0
- Dockerfile +25 -0
- README.md +143 -10
- build.gradle.kts +125 -0
- examples/camel-resources/camel-interface-resource.py +197 -0
- examples/camel-search-maths/README.md +91 -0
- examples/camel-search-maths/config.py +17 -0
- examples/camel-search-maths/interface/coral-agent.toml +10 -0
- examples/camel-search-maths/interface/marketplace-agent.toml +0 -0
- examples/camel-search-maths/math/coral-agent.toml +12 -0
- examples/camel-search-maths/mcp_example_camel_interface.py +74 -0
- examples/camel-search-maths/mcp_example_camel_math.py +68 -0
- examples/camel-search-maths/mcp_example_camel_search.py +76 -0
- examples/camel-search-maths/prompts.py +23 -0
- examples/camel-search-maths/requirements.txt +3 -0
- examples/camel-search-maths/search/coral-agent.toml +11 -0
- examples/camel-search-maths/tools.py +85 -0
- examples/camel-search-maths/venv.sh +2 -0
- examples/session-posts/Local docker session.http +41 -0
- examples/session-posts/application.yaml +84 -0
- gradle.properties +2 -0
- gradle/wrapper/gradle-wrapper.jar +0 -0
- gradle/wrapper/gradle-wrapper.properties +8 -0
- gradlew +234 -0
- gradlew.bat +89 -0
- images/thumnail2.png +3 -0
- settings.gradle.kts +5 -0
- src/main/kotlin/org/coralprotocol/coralserver/EventBus.kt +13 -0
- src/main/kotlin/org/coralprotocol/coralserver/IterHelpers.kt +10 -0
- src/main/kotlin/org/coralprotocol/coralserver/Main.kt +57 -0
- src/main/kotlin/org/coralprotocol/coralserver/agent/graph/GraphAgent.kt +43 -0
- src/main/kotlin/org/coralprotocol/coralserver/agent/graph/GraphAgentProvider.kt +36 -0
- src/main/kotlin/org/coralprotocol/coralserver/agent/graph/GraphAgentRequest.kt +27 -0
- src/main/kotlin/org/coralprotocol/coralserver/agent/graph/GraphAgentServer.kt +54 -0
- src/main/kotlin/org/coralprotocol/coralserver/agent/graph/GraphAgentServerScoring.kt +156 -0
- src/main/kotlin/org/coralprotocol/coralserver/agent/graph/GraphAgentServerSource.kt +21 -0
- src/main/kotlin/org/coralprotocol/coralserver/agent/registry/AgentExport.kt +36 -0
- src/main/kotlin/org/coralprotocol/coralserver/agent/registry/AgentOption.kt +60 -0
- src/main/kotlin/org/coralprotocol/coralserver/agent/registry/AgentOptionValue.kt +27 -0
- src/main/kotlin/org/coralprotocol/coralserver/agent/registry/AgentRegistry.kt +9 -0
.dockerignore
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.gradle
|
| 2 |
+
.venv
|
| 3 |
+
build
|
| 4 |
+
.direnv
|
| 5 |
+
.idea
|
| 6 |
+
examples
|
| 7 |
+
coralizer
|
.env
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# API Key for Model Provider
|
| 2 |
+
API_KEY=""
|
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
images/thumnail2.png filter=lfs diff=lfs merge=lfs -text
|
.github/workflows/docker.yml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: deploy-docker
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches:
|
| 6 |
+
- 'master'
|
| 7 |
+
jobs:
|
| 8 |
+
build-and-push-image:
|
| 9 |
+
runs-on: ubuntu-latest
|
| 10 |
+
permissions:
|
| 11 |
+
packages: write
|
| 12 |
+
steps:
|
| 13 |
+
- name: Checkout repository
|
| 14 |
+
uses: actions/checkout@v3
|
| 15 |
+
|
| 16 |
+
- name: Log in to the Container registry
|
| 17 |
+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
|
| 18 |
+
with:
|
| 19 |
+
registry: https://ghcr.io
|
| 20 |
+
username: ${{ github.actor }}
|
| 21 |
+
password: ${{ secrets.GITHUB_TOKEN }}
|
| 22 |
+
|
| 23 |
+
- name: Build and push Docker image
|
| 24 |
+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
|
| 25 |
+
with:
|
| 26 |
+
context: .
|
| 27 |
+
push: true
|
| 28 |
+
tags: ghcr.io/coral-protocol/coral-server:latest
|
.github/workflows/trufflehog.yml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
on:
|
| 2 |
+
push:
|
| 3 |
+
branches:
|
| 4 |
+
- master
|
| 5 |
+
pull_request:
|
| 6 |
+
|
| 7 |
+
jobs:
|
| 8 |
+
test:
|
| 9 |
+
runs-on: ubuntu-latest
|
| 10 |
+
steps:
|
| 11 |
+
- name: Checkout code
|
| 12 |
+
uses: actions/checkout@v4
|
| 13 |
+
with:
|
| 14 |
+
fetch-depth: 0
|
| 15 |
+
- name: Secret Scanning
|
| 16 |
+
uses: trufflesecurity/trufflehog@main
|
| 17 |
+
with:
|
| 18 |
+
extra_args: --results=verified,unknown
|
.gitignore
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.gradle
|
| 2 |
+
build/
|
| 3 |
+
!gradle/wrapper/gradle-wrapper.jar
|
| 4 |
+
!**/src/main/**/build/
|
| 5 |
+
!**/src/test/**/build/
|
| 6 |
+
|
| 7 |
+
### IntelliJ IDEA ###
|
| 8 |
+
.idea/AndroidProjectSystem.xml
|
| 9 |
+
.idea/modules.xml
|
| 10 |
+
.idea/jarRepositories.xml
|
| 11 |
+
.idea/compiler.xml
|
| 12 |
+
.idea/libraries/
|
| 13 |
+
.idea/misc.xml
|
| 14 |
+
.idea/gradle.xml
|
| 15 |
+
.idea/codeStyles/
|
| 16 |
+
*.iws
|
| 17 |
+
*.iml
|
| 18 |
+
*.ipr
|
| 19 |
+
out/
|
| 20 |
+
!**/src/main/**/out/
|
| 21 |
+
!**/src/test/**/out/
|
| 22 |
+
|
| 23 |
+
### Kotlin ###
|
| 24 |
+
.kotlin
|
| 25 |
+
|
| 26 |
+
### Eclipse ###
|
| 27 |
+
.apt_generated
|
| 28 |
+
.classpath
|
| 29 |
+
.factorypath
|
| 30 |
+
.project
|
| 31 |
+
.settings
|
| 32 |
+
.springBeans
|
| 33 |
+
.sts4-cache
|
| 34 |
+
bin/
|
| 35 |
+
!**/src/main/**/bin/
|
| 36 |
+
!**/src/test/**/bin/
|
| 37 |
+
|
| 38 |
+
### NetBeans ###
|
| 39 |
+
/nbproject/private/
|
| 40 |
+
/nbbuild/
|
| 41 |
+
/dist/
|
| 42 |
+
/nbdist/
|
| 43 |
+
/.nb-gradle/
|
| 44 |
+
|
| 45 |
+
### VS Code ###
|
| 46 |
+
.vscode/
|
| 47 |
+
|
| 48 |
+
### Mac OS ###
|
| 49 |
+
.DS_Store
|
| 50 |
+
|
| 51 |
+
### Python ###
|
| 52 |
+
**/*.venv
|
| 53 |
+
|
| 54 |
+
**/*.env
|
| 55 |
+
|
| 56 |
+
### Example directories ###
|
| 57 |
+
examples/camel-search-maths/__pycache__/
|
| 58 |
+
examples/session-posts/**.env.json
|
.idea/.gitignore
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Default ignored files
|
| 2 |
+
/shelf/
|
| 3 |
+
/workspace.xml
|
| 4 |
+
# Editor-based HTTP Client requests
|
| 5 |
+
/httpRequests/
|
| 6 |
+
# Datasource local storage ignored files
|
| 7 |
+
/dataSources/
|
| 8 |
+
/dataSources.local.xml
|
.idea/kotlinc.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="KotlinJpsPluginSettings">
|
| 4 |
+
<option name="version" value="2.1.20" />
|
| 5 |
+
</component>
|
| 6 |
+
</project>
|
.idea/material_theme_project_new.xml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="MaterialThemeProjectNewConfig">
|
| 4 |
+
<option name="metadata">
|
| 5 |
+
<MTProjectMetadataState>
|
| 6 |
+
<option name="migrated" value="true" />
|
| 7 |
+
<option name="pristineConfig" value="false" />
|
| 8 |
+
<option name="userId" value="-9d5f7b6:18d0e679a41:-8000" />
|
| 9 |
+
<option name="version" value="8.13.2" />
|
| 10 |
+
</MTProjectMetadataState>
|
| 11 |
+
</option>
|
| 12 |
+
</component>
|
| 13 |
+
</project>
|
.idea/vcs.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="VcsDirectoryMappings">
|
| 4 |
+
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
| 5 |
+
</component>
|
| 6 |
+
</project>
|
CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
We really appeciate and welcome all contributions!
|
| 2 |
+
|
| 3 |
+
By contributing via creating a pull request or pushing directly to this repo, you agree to assign your copyright of the contribution to the Coral Development Team when it is accepted (merged with or without minor changes). You assert that you have full power to assign the copyright, and that any copyright owned by or shared with a third party has been clearly marked with appropriate copyright notices. If you are employed, please check with your employer about the owernership of your contribution.
|
Dockerfile
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM gradle:8.14.2-jdk21-alpine AS build
|
| 2 |
+
COPY --chown=gradle:gradle . /home/gradle/src
|
| 3 |
+
WORKDIR /home/gradle/src
|
| 4 |
+
|
| 5 |
+
RUN jlink \
|
| 6 |
+
--verbose \
|
| 7 |
+
--add-modules java.base,jdk.unsupported,java.desktop,java.instrument,java.logging,java.management,java.sql,java.xml \
|
| 8 |
+
--compress 2 --strip-debug --no-header-files --no-man-pages \
|
| 9 |
+
--output /opt/minimal-java
|
| 10 |
+
|
| 11 |
+
RUN gradle build --no-daemon -x test
|
| 12 |
+
|
| 13 |
+
FROM alpine:3
|
| 14 |
+
|
| 15 |
+
ENV JAVA_HOME=/opt/minimal-java
|
| 16 |
+
ENV PATH="$JAVA_HOME/bin:$PATH"
|
| 17 |
+
|
| 18 |
+
ENV CONFIG_PATH="/config"
|
| 19 |
+
|
| 20 |
+
RUN mkdir /app
|
| 21 |
+
# Copy the custom minimal JRE from the builder stage
|
| 22 |
+
COPY --from=build "$JAVA_HOME" "$JAVA_HOME"
|
| 23 |
+
COPY --from=build /home/gradle/src/build/libs/ /app/
|
| 24 |
+
|
| 25 |
+
ENTRYPOINT ["java","-jar", "/app/coral-server-1.0-SNAPSHOT.jar"]
|
README.md
CHANGED
|
@@ -1,10 +1,143 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Coral Server - Agent Fuzzy A2A (Agent to Agent) Communication MCP Tools
|
| 2 |
+
|
| 3 |
+
An implementation of the Coral protocol that acts as an MCP server providing tools for agents to communicate with each other.
|
| 4 |
+

|
| 5 |
+
|
| 6 |
+
## Project Description
|
| 7 |
+
|
| 8 |
+
This project implements a Model Context Protocol (MCP) server that facilitates communication between AI agents through a thread-based messaging system.
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
Currently, it provides a set of tools that allow agents to:
|
| 12 |
+
|
| 13 |
+
- Register themselves in the system
|
| 14 |
+
- Create and manage conversation threads
|
| 15 |
+
- Send messages to threads
|
| 16 |
+
- Mention other agents in messages
|
| 17 |
+
- Receive notifications when mentioned
|
| 18 |
+
|
| 19 |
+
The server can be run in different modes (stdio, SSE) to support various integration scenarios.
|
| 20 |
+
|
| 21 |
+

|
| 22 |
+
|
| 23 |
+
### Status / future direction
|
| 24 |
+
This project is in its early stages and is not yet production-ready. The current focus is on building a robust foundation for agent communication, with plans to add more features and improve performance in the future.
|
| 25 |
+
|
| 26 |
+
Right now, this is "Local-mode" only, but we are working on a "Remote-mode" that will allow agents to communicate over the internet.
|
| 27 |
+
|
| 28 |
+
For remote mode, we will mostly preserve the interface provided by these MCP tools, but add server configuration options to allow for communicating with remote coral servers to add their agents to the society graph.
|
| 29 |
+
|
| 30 |
+
We don't want to re-invent the wheel, so we will reuse existing protocols and standards as much as possible.
|
| 31 |
+
Please don't hesitate to reach out if you want to be involved in coordinating any truly necessary standard changes or new standards with us.
|
| 32 |
+
|
| 33 |
+
## How to Run
|
| 34 |
+
|
| 35 |
+
### Quick example
|
| 36 |
+
This repo is a server that enables agents to communicate with each other, for an example of a full multi-agent system using this, check out
|
| 37 |
+
[the example here](/examples/camel-search-maths) or for a step-by-step guide to building agentic applications from scratch, follow this tutorial:
|
| 38 |
+
[https://github.com/Coral-Protocol/existing-agent-sessions-tutorial-private-temp](https://github.com/Coral-Protocol/existing-agent-sessions-tutorial-private-temp)
|
| 39 |
+
|
| 40 |
+
### Demo Video
|
| 41 |
+
|
| 42 |
+
[](https://youtu.be/MyokByTzY90)
|
| 43 |
+
*Click the image above to watch the demo video*
|
| 44 |
+
|
| 45 |
+
The project can be run in several modes:
|
| 46 |
+
|
| 47 |
+
### Using Gradle
|
| 48 |
+
|
| 49 |
+
```bash
|
| 50 |
+
# Run with SSE server using Ktor plugin (default, port 5555)
|
| 51 |
+
./gradlew run
|
| 52 |
+
|
| 53 |
+
# Run with custom arguments
|
| 54 |
+
./gradlew run --args="--stdio"
|
| 55 |
+
./gradlew run --args="--sse-server 5555"
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
### Using Docker
|
| 60 |
+
|
| 61 |
+
Install [Docker](https://docs.docker.com/desktop/)
|
| 62 |
+
|
| 63 |
+
```bash
|
| 64 |
+
# Build the Docker Image
|
| 65 |
+
docker build -t coral-server .
|
| 66 |
+
|
| 67 |
+
# Run the Docker Container
|
| 68 |
+
docker run -p 5555:5555 -v /path/to/your/coral-server/src/main/resources:/config coral-server
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
### Run Modes
|
| 72 |
+
|
| 73 |
+
- `--stdio`: Runs an MCP server using standard input/output
|
| 74 |
+
- `--sse-server-ktor <port>`: Runs an SSE MCP server using Ktor plugin (default if no argument is provided)
|
| 75 |
+
- `--sse-server <port>`: Runs an SSE MCP server with a plain configuration
|
| 76 |
+
|
| 77 |
+
## Available Tools
|
| 78 |
+
|
| 79 |
+
The server provides the following tools for agent communication:
|
| 80 |
+
|
| 81 |
+
### Agent Management
|
| 82 |
+
- `list_agents`: List all registered agents
|
| 83 |
+
|
| 84 |
+
### Thread Management
|
| 85 |
+
- `create_thread`: Create a new thread with participants
|
| 86 |
+
- `add_participant`: Add a participant to a thread
|
| 87 |
+
- `remove_participant`: Remove a participant from a thread
|
| 88 |
+
- `close_thread`: Close a thread with a summary
|
| 89 |
+
|
| 90 |
+
### Messaging
|
| 91 |
+
- `send_message`: Send a message to a thread
|
| 92 |
+
- `wait_for_mentions`: Wait for new messages mentioning an agent
|
| 93 |
+
|
| 94 |
+
## Connections (SSE Mode)
|
| 95 |
+
|
| 96 |
+
### Coral Server
|
| 97 |
+
You can connect to the server on:
|
| 98 |
+
|
| 99 |
+
```bash
|
| 100 |
+
http://localhost:5555/devmode/exampleApplication/privkey/session1/sse
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
### MCP Inspector
|
| 104 |
+
You can connect to the server using the MCP Inspector command:
|
| 105 |
+
|
| 106 |
+
```bash
|
| 107 |
+
npx @modelcontextprotocol/inspector sse --url http://localhost:5555/devmode/exampleApplication/privkey/session1/sse
|
| 108 |
+
```
|
| 109 |
+
### Register an Agent
|
| 110 |
+
You can register an agent to the Coral Server (also can be registered on MCP inspector) on:
|
| 111 |
+
|
| 112 |
+
```bash
|
| 113 |
+
http://localhost:5555/devmode/exampleApplication/privkey/session1/sse?agentId=test_agent
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
## Philosophy
|
| 118 |
+
|
| 119 |
+
Open infrastructure for the Society of AI Agents
|
| 120 |
+
|
| 121 |
+
It's a strange concept; we believe that much of what we now consider work will be handled by a different kind of society—a Society of AI Agents.
|
| 122 |
+
|
| 123 |
+
To bridge this gap, Coral Protocol was built as the connective tissue of this society. Coral is designed to enable agents to discover one another, communicate securely, exchange value, and scale their collaborative efforts from any framework.
|
| 124 |
+
|
| 125 |
+
We theorize that not only will this fix many problems with the composability of multi-agent systems, but it will also unlock their full potential to be much more capable and safe, this is due to the graph-like structure that prevents any one agent from holding too much power or becoming overwhelmed with too much responsibility.
|
| 126 |
+
|
| 127 |
+
## Contribution Guidelines
|
| 128 |
+
|
| 129 |
+
We welcome contributions! Email us at [hello@coralprotocol.org](mailto:hello@coralprotocol.org) or join our Discord [here](https://discord.gg/rMQc2uWXhj) to connect with the developer team. Feel free to open issues or submit pull requests.
|
| 130 |
+
|
| 131 |
+
Thanks for checking out the project, we hope you like it!
|
| 132 |
+
|
| 133 |
+
### Development
|
| 134 |
+
IntelliJ IDEA is recommended for development. The project uses Gradle as the build system.
|
| 135 |
+
|
| 136 |
+
To clone and import the project:
|
| 137 |
+
Go to File > New > Project from Version Control > Git.
|
| 138 |
+
enter `git@github.com:Coral-Protocol/coral-server.git`
|
| 139 |
+
Click Clone.
|
| 140 |
+
|
| 141 |
+
### Running from IntelliJ IDEA
|
| 142 |
+
You can click the play button next to the main method in the `Main.kt` file to run the server directly from IntelliJ IDEA.
|
| 143 |
+
|
build.gradle.kts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
plugins {
|
| 2 |
+
kotlin("jvm") version "2.1.20"
|
| 3 |
+
kotlin("plugin.serialization") version "2.1.20"
|
| 4 |
+
application
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
application {
|
| 8 |
+
mainClass.set("org.coralprotocol.coralserver.MainKt")
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
group = "org.coralprotocol"
|
| 12 |
+
version = "1.0-SNAPSHOT"
|
| 13 |
+
|
| 14 |
+
repositories {
|
| 15 |
+
mavenCentral()
|
| 16 |
+
maven {
|
| 17 |
+
url = uri("https://central.sonatype.com/repository/maven-snapshots/")
|
| 18 |
+
name = "sonatypeSnapshots"
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
maven("https://repo.repsy.io/mvn/chrynan/public")
|
| 22 |
+
maven("https://github.com/CaelumF/schema-kenerator/raw/develop/maven-repo")
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
dependencies {
|
| 27 |
+
testImplementation(kotlin("test"))
|
| 28 |
+
implementation("io.modelcontextprotocol:kotlin-sdk:0.5.0")
|
| 29 |
+
implementation("org.slf4j:slf4j-simple:2.0.9")
|
| 30 |
+
implementation("io.github.oshai:kotlin-logging-jvm:7.0.3")
|
| 31 |
+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.1")
|
| 32 |
+
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.8.1")
|
| 33 |
+
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1")
|
| 34 |
+
implementation("com.charleskorn.kaml:kaml:0.78.0") // YAML serialization
|
| 35 |
+
implementation("io.github.pdvrieze.xmlutil:core:0.91.0") // XML serialization
|
| 36 |
+
implementation("io.github.pdvrieze.xmlutil:serialization:0.91.0")
|
| 37 |
+
implementation("io.github.pdvrieze.xmlutil:core-jdk:0.91.0")
|
| 38 |
+
implementation("io.github.pdvrieze.xmlutil:serialization-jvm:0.91.0")
|
| 39 |
+
implementation("com.github.docker-java:docker-java:3.5.1")
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
// Hoplite for configuration
|
| 43 |
+
implementation("com.sksamuel.hoplite:hoplite-core:2.9.0")
|
| 44 |
+
implementation("com.sksamuel.hoplite:hoplite-yaml:2.9.0")
|
| 45 |
+
|
| 46 |
+
val ktorVersion = "3.0.2"
|
| 47 |
+
implementation(enforcedPlatform("io.ktor:ktor-bom:$ktorVersion"))
|
| 48 |
+
implementation("io.ktor:ktor-server-status-pages:${ktorVersion}")
|
| 49 |
+
|
| 50 |
+
val uriVersion="0.5.0"
|
| 51 |
+
implementation("com.chrynan.uri.core:uri-core:$uriVersion")
|
| 52 |
+
implementation("com.chrynan.uri.core:uri-ktor-client:$uriVersion")
|
| 53 |
+
|
| 54 |
+
// Ktor testing dependencies
|
| 55 |
+
testImplementation("io.ktor:ktor-server-test-host")
|
| 56 |
+
testImplementation("io.ktor:ktor-client-mock")
|
| 57 |
+
val arcVersion = "0.126.0"
|
| 58 |
+
// Arc agents for E2E tests
|
| 59 |
+
testImplementation("org.eclipse.lmos:arc-agents:$arcVersion")
|
| 60 |
+
testImplementation("org.eclipse.lmos:arc-mcp:$arcVersion")
|
| 61 |
+
testImplementation("org.eclipse.lmos:arc-server:$arcVersion")
|
| 62 |
+
testImplementation("org.eclipse.lmos:arc-azure-client:$arcVersion")
|
| 63 |
+
testImplementation("org.eclipse.lmos:arc-langchain4j-client:$arcVersion")
|
| 64 |
+
testImplementation("io.modelcontextprotocol.sdk:mcp:0.11.0-SNAPSHOT") // Override MCP Java client for Arc 0.126.0
|
| 65 |
+
testImplementation("io.mockk:mockk:1.14.2")
|
| 66 |
+
|
| 67 |
+
// kotest
|
| 68 |
+
// TODO: Use kotest for some or all tests
|
| 69 |
+
// val kotestVersion = "5.9.1"
|
| 70 |
+
// testImplementation("io.kotest:kotest-runner-junit5:$kotestVersion")
|
| 71 |
+
// testImplementation("io.kotest:kotest-assertions-core:$kotestVersion")
|
| 72 |
+
// testImplementation("io.kotest:kotest-property:$kotestVersion")
|
| 73 |
+
|
| 74 |
+
// Ktor client dependencies
|
| 75 |
+
implementation("io.ktor:ktor-client-logging")
|
| 76 |
+
implementation("io.ktor:ktor-client-content-negotiation")
|
| 77 |
+
implementation("io.ktor:ktor-client-cio-jvm")
|
| 78 |
+
implementation("io.ktor:ktor-serialization-kotlinx-json")
|
| 79 |
+
implementation("io.ktor:ktor-client-plugins")
|
| 80 |
+
|
| 81 |
+
implementation("net.pwall.json:json-kotlin-schema:0.56")
|
| 82 |
+
|
| 83 |
+
// Ktor server dependencies
|
| 84 |
+
implementation("io.ktor:ktor-server-core")
|
| 85 |
+
implementation("io.ktor:ktor-server-cio")
|
| 86 |
+
implementation("io.ktor:ktor-server-sse")
|
| 87 |
+
implementation("io.ktor:ktor-server-html-builder")
|
| 88 |
+
implementation("io.ktor:ktor-server-cors")
|
| 89 |
+
implementation("io.ktor:ktor-server-content-negotiation")
|
| 90 |
+
implementation("io.ktor:ktor-server-resources")
|
| 91 |
+
testImplementation("io.ktor:ktor-server-core")
|
| 92 |
+
testImplementation("io.ktor:ktor-server-cio")
|
| 93 |
+
testImplementation("io.ktor:ktor-server-sse")
|
| 94 |
+
|
| 95 |
+
// TOML serialization
|
| 96 |
+
implementation("com.akuleshov7:ktoml-core:0.7.0")
|
| 97 |
+
implementation("com.akuleshov7:ktoml-file:0.7.0")
|
| 98 |
+
|
| 99 |
+
// OpenAPI
|
| 100 |
+
val ktorToolsVersion = "5.2.0"
|
| 101 |
+
implementation("io.github.smiley4:ktor-openapi:${ktorToolsVersion}")
|
| 102 |
+
implementation("io.github.smiley4:ktor-redoc:${ktorToolsVersion}")
|
| 103 |
+
|
| 104 |
+
val schemaVersion = "2.4.0.1"
|
| 105 |
+
implementation("io.github.smiley4:schema-kenerator-core:${schemaVersion}")
|
| 106 |
+
implementation("io.github.smiley4:schema-kenerator-serialization:${schemaVersion}")
|
| 107 |
+
implementation("io.github.smiley4:schema-kenerator-swagger:${schemaVersion}")
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
tasks.test {
|
| 111 |
+
useJUnitPlatform()
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
tasks.jar {
|
| 115 |
+
manifest {
|
| 116 |
+
attributes["Main-Class"] = "org.coralprotocol.coralserver.MainKt"
|
| 117 |
+
}
|
| 118 |
+
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
|
| 119 |
+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
| 120 |
+
exclude("META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA")
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
kotlin {
|
| 124 |
+
jvmToolchain(21)
|
| 125 |
+
}
|
examples/camel-resources/camel-interface-resource.py
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
import os
|
| 3 |
+
import json
|
| 4 |
+
from camel.toolkits.mcp_toolkit import MCPClient
|
| 5 |
+
from camel.toolkits import HumanToolkit, MCPToolkit
|
| 6 |
+
from camel.models import ModelFactory
|
| 7 |
+
from camel.types import ModelPlatformType, ModelType
|
| 8 |
+
from camel.agents import ChatAgent
|
| 9 |
+
import urllib.parse
|
| 10 |
+
import base64
|
| 11 |
+
from mcp import ClientSession
|
| 12 |
+
from mcp.types import BlobResourceContents, ResourceContents, TextResourceContents
|
| 13 |
+
from typing import Union, Optional, List
|
| 14 |
+
|
| 15 |
+
async def get_tools_description(tools):
|
| 16 |
+
descriptions = []
|
| 17 |
+
for tool in tools:
|
| 18 |
+
tool_name = getattr(tool.func, '__name__', 'unknown_tool')
|
| 19 |
+
schema = tool.get_openai_function_schema() or {}
|
| 20 |
+
arg_names = list(schema.get('parameters', {}).get('properties', {}).keys()) if schema else []
|
| 21 |
+
description = tool.get_function_description() or 'No description'
|
| 22 |
+
schema_str = json.dumps(schema, default=str).replace('{', '{{').replace('}', '}}')
|
| 23 |
+
descriptions.append(
|
| 24 |
+
f"Tool: {tool_name}, Args: {arg_names}, Description: {description}, Schema: {schema_str}"
|
| 25 |
+
)
|
| 26 |
+
return "\n".join(descriptions)
|
| 27 |
+
|
| 28 |
+
class SimpleBlob:
|
| 29 |
+
"""A simple class to hold resource data, MIME type, and metadata."""
|
| 30 |
+
def __init__(self, data: Union[str, bytes], mime_type: Optional[str], metadata: dict):
|
| 31 |
+
self.data = data
|
| 32 |
+
self.mime_type = mime_type
|
| 33 |
+
self.metadata = metadata
|
| 34 |
+
|
| 35 |
+
@classmethod
|
| 36 |
+
def from_data(cls, data: Union[str, bytes], mime_type: Optional[str] = None, metadata: Optional[dict] = None):
|
| 37 |
+
"""Create a SimpleBlob from data."""
|
| 38 |
+
return cls(data=data, mime_type=mime_type, metadata=metadata or {})
|
| 39 |
+
|
| 40 |
+
def convert_mcp_resource_to_blob(
|
| 41 |
+
resource_uri: str,
|
| 42 |
+
contents: ResourceContents,
|
| 43 |
+
) -> SimpleBlob:
|
| 44 |
+
if isinstance(contents, TextResourceContents):
|
| 45 |
+
data = contents.text
|
| 46 |
+
elif isinstance(contents, BlobResourceContents):
|
| 47 |
+
data = base64.b64decode(contents.blob)
|
| 48 |
+
else:
|
| 49 |
+
raise ValueError(f"Unsupported content type for URI {resource_uri}")
|
| 50 |
+
return SimpleBlob.from_data(
|
| 51 |
+
data=data,
|
| 52 |
+
mime_type=contents.mimeType,
|
| 53 |
+
metadata={"uri": resource_uri},
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
async def get_mcp_resource(session: ClientSession, uri: str) -> List[SimpleBlob]:
|
| 57 |
+
contents_result = await session.read_resource(uri)
|
| 58 |
+
if not contents_result.contents or len(contents_result.contents) == 0:
|
| 59 |
+
return []
|
| 60 |
+
return [
|
| 61 |
+
convert_mcp_resource_to_blob(uri, content) for content in contents_result.contents
|
| 62 |
+
]
|
| 63 |
+
|
| 64 |
+
async def load_mcp_resources(
|
| 65 |
+
session: ClientSession,
|
| 66 |
+
uris: Union[str, List[str], None] = None,
|
| 67 |
+
) -> List[SimpleBlob]:
|
| 68 |
+
blobs = []
|
| 69 |
+
if uris is None:
|
| 70 |
+
resources_list = await session.list_resources()
|
| 71 |
+
uri_list = [r.uri for r in resources_list.resources]
|
| 72 |
+
elif isinstance(uris, str):
|
| 73 |
+
uri_list = [uris]
|
| 74 |
+
else:
|
| 75 |
+
uri_list = uris
|
| 76 |
+
for uri in uri_list:
|
| 77 |
+
try:
|
| 78 |
+
resource_blobs = await get_mcp_resource(session, uri)
|
| 79 |
+
blobs.extend(resource_blobs)
|
| 80 |
+
except Exception as e:
|
| 81 |
+
print(f"Error fetching resource {uri}: {e}")
|
| 82 |
+
continue
|
| 83 |
+
return blobs
|
| 84 |
+
|
| 85 |
+
async def get_resources(
|
| 86 |
+
client: MCPClient,
|
| 87 |
+
uris: Union[str, List[str], None] = None
|
| 88 |
+
) -> List[SimpleBlob]:
|
| 89 |
+
"""Get resources from the MCP server.
|
| 90 |
+
|
| 91 |
+
Args:
|
| 92 |
+
client: MCPClient instance
|
| 93 |
+
uris: Optional resource URI or list of URIs to load. If None, fetches all resources.
|
| 94 |
+
|
| 95 |
+
Returns:
|
| 96 |
+
A list of SimpleBlob objects
|
| 97 |
+
"""
|
| 98 |
+
if client.session is None:
|
| 99 |
+
raise RuntimeError("MCPClient is not connected or session is not initialized.")
|
| 100 |
+
try:
|
| 101 |
+
return await load_mcp_resources(client.session, uris)
|
| 102 |
+
except Exception as e:
|
| 103 |
+
raise RuntimeError(f"Error fetching resources: {e}")
|
| 104 |
+
|
| 105 |
+
async def main():
|
| 106 |
+
base_url_1 = "http://localhost:5555/devmode/exampleApplication/privkey/session1/sse"
|
| 107 |
+
params_1 = {
|
| 108 |
+
"waitForAgents": 1,
|
| 109 |
+
"agentId": "user_interface_agent",
|
| 110 |
+
"agentDescription": "You are user_interaction_agent, responsible for engaging with users, processing instructions, and coordinating with other agents"
|
| 111 |
+
}
|
| 112 |
+
query_string = urllib.parse.urlencode(params_1)
|
| 113 |
+
MCP_SERVER_URL_1 = f"{base_url_1}?{query_string}"
|
| 114 |
+
|
| 115 |
+
coral_server = MCPClient(
|
| 116 |
+
command_or_url=MCP_SERVER_URL_1,
|
| 117 |
+
timeout=300.0
|
| 118 |
+
)
|
| 119 |
+
await coral_server.__aenter__()
|
| 120 |
+
print(f"Connected to MCP server as user_interface_agent at {MCP_SERVER_URL_1}")
|
| 121 |
+
|
| 122 |
+
model = ModelFactory.create(
|
| 123 |
+
model_platform=ModelPlatformType.OPENAI,
|
| 124 |
+
model_type=ModelType.GPT_4O_MINI,
|
| 125 |
+
api_key=os.getenv("OPENAI_API_KEY"),
|
| 126 |
+
model_config_dict={"temperature": 0.3, "max_tokens": 16000},
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
while True:
|
| 130 |
+
try:
|
| 131 |
+
resources = await get_resources(coral_server, uris=None)
|
| 132 |
+
if not resources:
|
| 133 |
+
agent_resources = "NA"
|
| 134 |
+
print("No resources found.")
|
| 135 |
+
else:
|
| 136 |
+
agent_resources = "\n".join(str(blob.data) for blob in resources)
|
| 137 |
+
print("Resources fetched:")
|
| 138 |
+
# for blob in resources:
|
| 139 |
+
# print(blob.data)
|
| 140 |
+
except Exception as e:
|
| 141 |
+
print(f"Error retrieving resources: {e}")
|
| 142 |
+
agent_resources = "NA"
|
| 143 |
+
|
| 144 |
+
resource_sys_message = agent_resources
|
| 145 |
+
|
| 146 |
+
mcp_toolkit = MCPToolkit([coral_server])
|
| 147 |
+
tools = mcp_toolkit.get_tools() + HumanToolkit().get_tools()
|
| 148 |
+
tools_description = await get_tools_description(tools)
|
| 149 |
+
|
| 150 |
+
sys_msg = (
|
| 151 |
+
f"""You are an agent interacting with the tools from Coral Server and having your own Human Tool to ask have a conversation with Human.
|
| 152 |
+
Your resources, provided in `resource_sys_message`, contain thread-based conversations between agents in XML format.
|
| 153 |
+
Each thread includes details such as thread ID, participant agent IDs, message content, and timestamps.
|
| 154 |
+
Use these resources to understand past agent interactions and inform your decisions when coordinating with other agents or responding to user queries.
|
| 155 |
+
|
| 156 |
+
Follow these steps in order:
|
| 157 |
+
1. Use `list_agents` to list all connected agents and get their descriptions.
|
| 158 |
+
2. Use `ask_human_via_console` to ask, "How can I assist you today?" and capture expect response.
|
| 159 |
+
3. Take 2 seconds to think and understand the user's intent and decide the right agent to handle the request based on list of agents.
|
| 160 |
+
4. If the user wants any information about the coral server, use the tools to get the information and pass it to the user. Do not send any message to any other agent, just give the information and go to Step 1.
|
| 161 |
+
5. Once you have the right agent, use `create_thread` to create a thread with the selected agent. If no agent is available, use the `ask_human` tool to specify the agent you want to use.
|
| 162 |
+
6. Use your logic to determine the task you want that agent to perform and create a message for them which instructs the agent to perform the task called "instruction".
|
| 163 |
+
7. Use `send_message` to send a message in the thread, mentioning the selected agent, with content: "instructions".
|
| 164 |
+
8. Use `wait_for_mentions` with a 30 seconds timeout to wait for a response from the agent you mentioned.
|
| 165 |
+
9. Show the entire conversation in the thread to the user.
|
| 166 |
+
10. Wait for 3 seconds and then use `ask_human` to ask the user if they need anything else and keep waiting for their response.
|
| 167 |
+
11. If the user asks for something else, repeat the process from step 1.
|
| 168 |
+
|
| 169 |
+
Use only listed tools: {tools_description}
|
| 170 |
+
Your resources are: {resource_sys_message}"""
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
camel_agent = ChatAgent(
|
| 174 |
+
system_message=sys_msg,
|
| 175 |
+
model=model,
|
| 176 |
+
tools=tools,
|
| 177 |
+
)
|
| 178 |
+
print("ChatAgent initialized with updated resources!")
|
| 179 |
+
print("Resource System Message before agent question:")
|
| 180 |
+
print(resource_sys_message)
|
| 181 |
+
|
| 182 |
+
prompt = "As the user_interaction_agent on the Coral Server, initiate your workflow by listing all connected agents and asking the user how you can assist them."
|
| 183 |
+
try:
|
| 184 |
+
response = await camel_agent.astep(prompt)
|
| 185 |
+
print("Agent Reply:")
|
| 186 |
+
print(response.msgs[0].content)
|
| 187 |
+
except Exception as e:
|
| 188 |
+
print(f"Error processing agent response: {e}")
|
| 189 |
+
|
| 190 |
+
await asyncio.sleep(3)
|
| 191 |
+
|
| 192 |
+
continue
|
| 193 |
+
|
| 194 |
+
await coral_server.__aexit__(None, None, None)
|
| 195 |
+
|
| 196 |
+
if __name__ == "__main__":
|
| 197 |
+
asyncio.run(main())
|
examples/camel-search-maths/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
In this example we have 3 agents implemented with CAMEL working together to answer a user query.
|
| 2 |
+
|
| 3 |
+
To run it, you need to have the dependencies installed:
|
| 4 |
+
|
| 5 |
+
# Running the example
|
| 6 |
+
|
| 7 |
+
# 1. Install the dependencies
|
| 8 |
+
```bash
|
| 9 |
+
pip install -r requirements.txt
|
| 10 |
+
```
|
| 11 |
+
|
| 12 |
+
You will need to install CAMEL with all optional dependencies until they fix the minimal requirements version.
|
| 13 |
+
|
| 14 |
+
```bash
|
| 15 |
+
pip install "camel-ai[all]"
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
## 2. Start the server
|
| 19 |
+
Cd to this project's root directory and run the server.
|
| 20 |
+
```bash
|
| 21 |
+
./gradlew run
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
Note that gradle will show "83"% forever, but it is actually running. You can check the logs in the terminal to see if it is up and running.
|
| 25 |
+
|
| 26 |
+
## 3. Run the agents
|
| 27 |
+
Ensure you have an OPENAI_API_KEY set in your environment variables (or change to a different model in the agents)
|
| 28 |
+
|
| 29 |
+
Before running the agents, you can configure the model settings in `config.py`:
|
| 30 |
+
```python
|
| 31 |
+
# Model Configuration
|
| 32 |
+
PLATFORM_TYPE = "OPENAI" # Change the model provider
|
| 33 |
+
MODEL_TYPE = "GPT_4O" # Change the model type
|
| 34 |
+
|
| 35 |
+
# Model Settings
|
| 36 |
+
MODEL_CONFIG = {
|
| 37 |
+
"temperature": 0.3, # Adjust model parameters
|
| 38 |
+
"max_tokens": 4096,
|
| 39 |
+
}
|
| 40 |
+
```
|
| 41 |
+
For available model providers and types, refer to the [CAMEL model types documentation](https://github.com/camel-ai/camel/blob/master/camel/types/enums.py).
|
| 42 |
+
|
| 43 |
+
In a separate terminal, run the agents. They all need to be running for this example to work.
|
| 44 |
+
|
| 45 |
+
```bash
|
| 46 |
+
python mcp_example_camel_math.py
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
```bash
|
| 50 |
+
python mcp_example_camel_search.py
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
```bash
|
| 54 |
+
python mcp_example_camel_interface.py
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
## 4. Interact with the agents
|
| 59 |
+
|
| 60 |
+
You will eventually see the interface agent asking for your query via STDIN. Write your query and hit enter.
|
| 61 |
+
Try asking for example:
|
| 62 |
+
|
| 63 |
+
```
|
| 64 |
+
What is the square root of the area of Konstanz?
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
The society will then work together to address your query, and the interface agent will share their findings with you.
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
## Troubleshooting
|
| 71 |
+
The agents are limited to iterate only 20 times to prevent accidental API expenses, so they might need restarting if they've been alive too long.
|
| 72 |
+
|
| 73 |
+
Also right now the agents will not be unregistered, so make sure to restart the server if you want to run them again.
|
| 74 |
+
|
| 75 |
+
This is very early, so we welcome any questions no matter how silly they might seem so we can improve the documentation and Dev Experience!
|
| 76 |
+
|
| 77 |
+
Come by our Discord for any questions or suggestions: https://discord.gg/cDzGHnzkwD
|
| 78 |
+
|
| 79 |
+
---
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
# Build on the example
|
| 83 |
+
Now that you've got your society running, you can build on it.
|
| 84 |
+
|
| 85 |
+
Adding another agent is as simple as copying and pasting one of these agent files and running it too.
|
| 86 |
+
Don't forget to prompt it to assume a different name.
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
# Future potential
|
| 90 |
+
At the time of writing, this is a proof of concept. Server and agent lifecycle questions remain.
|
| 91 |
+
The scope of this project includes answering these questions with remote mode and sessions.
|
examples/camel-search-maths/config.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Configuration file for model settings"""
|
| 2 |
+
|
| 3 |
+
# Model Configuration
|
| 4 |
+
# for more information on the models, see https://github.com/camel-ai/camel/blob/master/camel/types/enums.py
|
| 5 |
+
|
| 6 |
+
PLATFORM_TYPE = "OPENAI"
|
| 7 |
+
MODEL_TYPE = "GPT_4O"
|
| 8 |
+
|
| 9 |
+
# Model Settings
|
| 10 |
+
MODEL_CONFIG = {
|
| 11 |
+
"temperature": 0.3,
|
| 12 |
+
"max_tokens": 4096,
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
# Agent Settings
|
| 16 |
+
MESSAGE_WINDOW_SIZE = 4096 * 50
|
| 17 |
+
TOKEN_LIMIT = 20000
|
examples/camel-search-maths/interface/coral-agent.toml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[agent]
|
| 2 |
+
name = "interface"
|
| 3 |
+
version = "0.0.1"
|
| 4 |
+
|
| 5 |
+
[options.OPENAI_API_KEY]
|
| 6 |
+
type = "string"
|
| 7 |
+
description = "OpenAI API Key"
|
| 8 |
+
|
| 9 |
+
[runtimes.executable]
|
| 10 |
+
command = ["bash", "examples/camel-search-maths/venv.sh", "examples/camel-search-maths/mcp_example_camel_interface.py"]
|
examples/camel-search-maths/interface/marketplace-agent.toml
ADDED
|
File without changes
|
examples/camel-search-maths/math/coral-agent.toml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[agent]
|
| 2 |
+
name = "math"
|
| 3 |
+
version = "0.0.1"
|
| 4 |
+
|
| 5 |
+
[options.OPENAI_API_KEY]
|
| 6 |
+
type = "string"
|
| 7 |
+
description = "OpenAI API Key"
|
| 8 |
+
|
| 9 |
+
#OPENAI_API_KEY = { type = "string", description = "OpenAI API Key" }
|
| 10 |
+
|
| 11 |
+
[runtimes.executable]
|
| 12 |
+
command = ["bash", "examples/camel-search-maths/venv.sh", "examples/camel-search-maths/mcp_example_camel_math.py"]
|
examples/camel-search-maths/mcp_example_camel_interface.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio # Manages asynchronous operations
|
| 2 |
+
import os # Provide interaction with the operating system.
|
| 3 |
+
from time import sleep
|
| 4 |
+
|
| 5 |
+
from camel.agents import ChatAgent # creates Agents
|
| 6 |
+
from camel.models import ModelFactory # encapsulates LLM
|
| 7 |
+
from camel.toolkits import HumanToolkit, MCPToolkit # import tools
|
| 8 |
+
from camel.toolkits.mcp_toolkit import MCPClient
|
| 9 |
+
from camel.utils.mcp_client import ServerConfig
|
| 10 |
+
from camel.types import ModelPlatformType, ModelType
|
| 11 |
+
from dotenv import load_dotenv
|
| 12 |
+
|
| 13 |
+
from config import PLATFORM_TYPE, MODEL_TYPE, MODEL_CONFIG, MESSAGE_WINDOW_SIZE, TOKEN_LIMIT
|
| 14 |
+
|
| 15 |
+
# load_dotenv()
|
| 16 |
+
|
| 17 |
+
from prompts import get_tools_description, get_user_message
|
| 18 |
+
|
| 19 |
+
async def main():
|
| 20 |
+
# Simply add the Coral server address as a tool
|
| 21 |
+
coral_url = os.getenv("CORAL_CONNECTION_URL", default = "http://localhost:5555/devmode/exampleApplication/privkey/session1/sse?waitForAgents=3&agentId=user_interaction_agent")
|
| 22 |
+
server = MCPClient(ServerConfig(url=coral_url, timeout=3000000.0, sse_read_timeout=3000000.0, terminate_on_close=True, prefer_sse=True), timeout=3000000.0)
|
| 23 |
+
|
| 24 |
+
mcp_toolkit = MCPToolkit([server])
|
| 25 |
+
|
| 26 |
+
async with mcp_toolkit as connected_mcp_toolkit:
|
| 27 |
+
print("Connected to coral server.")
|
| 28 |
+
camel_agent = await create_interface_agent(connected_mcp_toolkit)
|
| 29 |
+
|
| 30 |
+
# Step the agent continuously
|
| 31 |
+
for i in range(20): #This should be infinite, but for testing we limit it to 20 to avoid accidental API fees
|
| 32 |
+
resp = await camel_agent.astep(get_user_message())
|
| 33 |
+
msgzero = resp.msgs[0]
|
| 34 |
+
msgzerojson = msgzero.to_dict()
|
| 35 |
+
print(msgzerojson)
|
| 36 |
+
sleep(10)
|
| 37 |
+
|
| 38 |
+
async def create_interface_agent(connected_mcp_toolkit):
|
| 39 |
+
tools = connected_mcp_toolkit.get_tools()
|
| 40 |
+
sys_msg = (
|
| 41 |
+
f"""
|
| 42 |
+
You are a helpful assistant responsible for interacting with the user and working with other agents to meet the user's requests. You can interact with other agents using the chat tools.
|
| 43 |
+
User interaction is your speciality. You identify as "{os.getenv("CORAL_AGENT_ID", default = "N/A")}".
|
| 44 |
+
|
| 45 |
+
As a user interaction agent, only you can interact with the user. Use the user_input tool to get new tasks from the user.
|
| 46 |
+
|
| 47 |
+
Make sure that all information comes from reliable sources and that all calculations are done using the appropriate tools by the appropriate agents. Make sure your responses are much more reliable than guesses! You should make sure no agents are guessing too, by suggesting the relevant agents to do each part of a task to the agents you are working with. Do a refresh of the available agents before asking the user for input.
|
| 48 |
+
|
| 49 |
+
Make sure to put the name of the agent(s) you are talking to in the mentions field of the send message tool.
|
| 50 |
+
|
| 51 |
+
{os.getenv("CORAL_PROMPT_SYSTEM", default = "")}
|
| 52 |
+
|
| 53 |
+
Here are the guidelines for using the communication tools:
|
| 54 |
+
{get_tools_description()}
|
| 55 |
+
"""
|
| 56 |
+
)
|
| 57 |
+
model = ModelFactory.create(
|
| 58 |
+
model_platform=ModelPlatformType[PLATFORM_TYPE],
|
| 59 |
+
model_type=ModelType[MODEL_TYPE],
|
| 60 |
+
api_key=os.getenv("API_KEY"),
|
| 61 |
+
model_config_dict=MODEL_CONFIG,
|
| 62 |
+
)
|
| 63 |
+
camel_agent = ChatAgent( # create agent with our mcp tools
|
| 64 |
+
system_message=sys_msg,
|
| 65 |
+
model=model,
|
| 66 |
+
tools=tools,
|
| 67 |
+
message_window_size=MESSAGE_WINDOW_SIZE,
|
| 68 |
+
token_limit=TOKEN_LIMIT
|
| 69 |
+
)
|
| 70 |
+
return camel_agent
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
if __name__ == "__main__":
|
| 74 |
+
asyncio.run(main())
|
examples/camel-search-maths/mcp_example_camel_math.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
import os
|
| 3 |
+
from time import sleep
|
| 4 |
+
|
| 5 |
+
from camel.agents import ChatAgent
|
| 6 |
+
from camel.models import ModelFactory
|
| 7 |
+
from camel.toolkits import MCPToolkit, MathToolkit
|
| 8 |
+
from camel.utils.mcp_client import ServerConfig
|
| 9 |
+
from camel.toolkits.mcp_toolkit import MCPClient
|
| 10 |
+
from camel.types import ModelPlatformType, ModelType
|
| 11 |
+
from prompts import get_tools_description, get_user_message
|
| 12 |
+
from dotenv import load_dotenv
|
| 13 |
+
from config import PLATFORM_TYPE, MODEL_TYPE, MODEL_CONFIG, MESSAGE_WINDOW_SIZE, TOKEN_LIMIT
|
| 14 |
+
|
| 15 |
+
# load_dotenv()
|
| 16 |
+
|
| 17 |
+
async def main():
|
| 18 |
+
# Simply add the Coral server address as a tool
|
| 19 |
+
print("Starting MCP client...")
|
| 20 |
+
coral_url = os.getenv("CORAL_CONNECTION_URL", default = "http://localhost:5555/devmode/exampleApplication/privkey/session1/sse?agentId=math_agent")
|
| 21 |
+
server = MCPClient(ServerConfig(url=coral_url, timeout=3000000.0, sse_read_timeout=3000000.0, terminate_on_close=True, prefer_sse=True), timeout=3000000.0)
|
| 22 |
+
mcp_toolkit = MCPToolkit([server])
|
| 23 |
+
|
| 24 |
+
async with mcp_toolkit as connected_mcp_toolkit:
|
| 25 |
+
tools = connected_mcp_toolkit.get_tools() + MathToolkit().get_tools()
|
| 26 |
+
camel_agent = await create_math_agent(tools)
|
| 27 |
+
|
| 28 |
+
# Step the agent continuously
|
| 29 |
+
for i in range(20): #This should be infinite, but for testing we limit it to 20 to avoid accidental API fees
|
| 30 |
+
resp = await camel_agent.astep(get_user_message())
|
| 31 |
+
msgzero = resp.msgs[0]
|
| 32 |
+
msgzerojson = msgzero.to_dict()
|
| 33 |
+
print(msgzerojson)
|
| 34 |
+
sleep(10)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
async def create_math_agent(tools):
|
| 38 |
+
sys_msg = (
|
| 39 |
+
f"""
|
| 40 |
+
You are a helpful assistant responsible for doing maths
|
| 41 |
+
operations. You can interact with other agents using the chat tools.
|
| 42 |
+
Mathematics are your speciality. You identify as "math_agent".
|
| 43 |
+
|
| 44 |
+
If you have no tasks yet, call the wait for mentions tool. Don't ask agents for tasks, wait for them to ask you.
|
| 45 |
+
{os.getenv("CORAL_PROMPT_SYSTEM", default = "")}
|
| 46 |
+
|
| 47 |
+
Here are the guidelines for using the communication tools:
|
| 48 |
+
{get_tools_description()}
|
| 49 |
+
"""
|
| 50 |
+
)
|
| 51 |
+
model = ModelFactory.create(
|
| 52 |
+
model_platform=ModelPlatformType[PLATFORM_TYPE],
|
| 53 |
+
model_type=ModelType[MODEL_TYPE],
|
| 54 |
+
api_key=os.getenv("API_KEY"),
|
| 55 |
+
model_config_dict=MODEL_CONFIG,
|
| 56 |
+
)
|
| 57 |
+
camel_agent = ChatAgent(
|
| 58 |
+
system_message=sys_msg,
|
| 59 |
+
model=model,
|
| 60 |
+
tools=tools,
|
| 61 |
+
message_window_size=MESSAGE_WINDOW_SIZE,
|
| 62 |
+
token_limit=TOKEN_LIMIT
|
| 63 |
+
)
|
| 64 |
+
return camel_agent
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
if __name__ == "__main__":
|
| 68 |
+
asyncio.run(main())
|
examples/camel-search-maths/mcp_example_camel_search.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
import os
|
| 3 |
+
from time import sleep
|
| 4 |
+
|
| 5 |
+
from camel.agents import ChatAgent
|
| 6 |
+
from camel.models import ModelFactory
|
| 7 |
+
from camel.toolkits import FunctionTool, MCPToolkit
|
| 8 |
+
from camel.toolkits.mcp_toolkit import MCPClient
|
| 9 |
+
from camel.utils.mcp_client import ServerConfig
|
| 10 |
+
from camel.toolkits.search_toolkit import SearchToolkit
|
| 11 |
+
from camel.types import ModelPlatformType, ModelType
|
| 12 |
+
|
| 13 |
+
from prompts import get_tools_description, get_user_message
|
| 14 |
+
from tools import JinaBrowsingToolkit
|
| 15 |
+
from dotenv import load_dotenv
|
| 16 |
+
from config import PLATFORM_TYPE, MODEL_TYPE, MODEL_CONFIG, MESSAGE_WINDOW_SIZE, TOKEN_LIMIT
|
| 17 |
+
|
| 18 |
+
# load_dotenv()
|
| 19 |
+
|
| 20 |
+
async def main():
|
| 21 |
+
# Simply add the Coral server address as a tool
|
| 22 |
+
coral_url = os.getenv("CORAL_CONNECTION_URL", default = "http://localhost:5555/devmode/exampleApplication/privkey/session1/sse?waitForAgents=3&agentId=search_agent")
|
| 23 |
+
server = MCPClient(ServerConfig(url=coral_url, timeout=3000000.0, sse_read_timeout=3000000.0, terminate_on_close=True, prefer_sse=True), timeout=3000000.0)
|
| 24 |
+
mcp_toolkit = MCPToolkit([server])
|
| 25 |
+
|
| 26 |
+
async with mcp_toolkit as connected_mcp_toolkit:
|
| 27 |
+
camel_agent = await create_search_agent(connected_mcp_toolkit)
|
| 28 |
+
|
| 29 |
+
# Step the agent continuously
|
| 30 |
+
for i in range(20): #This should be infinite, but for testing we limit it to 20 to avoid accidental API fees
|
| 31 |
+
resp = await camel_agent.astep(get_user_message())
|
| 32 |
+
msgzero = resp.msgs[0]
|
| 33 |
+
msgzerojson = msgzero.to_dict()
|
| 34 |
+
print(msgzerojson)
|
| 35 |
+
sleep(10)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
async def create_search_agent(connected_mcp_toolkit):
|
| 39 |
+
search_toolkit = SearchToolkit()
|
| 40 |
+
browse_toolkit = JinaBrowsingToolkit()
|
| 41 |
+
search_tools = [
|
| 42 |
+
FunctionTool(search_toolkit.search_google),
|
| 43 |
+
FunctionTool(browse_toolkit.get_url_content),
|
| 44 |
+
FunctionTool(browse_toolkit.get_url_content_with_context),
|
| 45 |
+
]
|
| 46 |
+
tools = connected_mcp_toolkit.get_tools() + search_tools
|
| 47 |
+
sys_msg = (
|
| 48 |
+
f"""
|
| 49 |
+
You are a helpful assistant responsible for doing search operations. You can interact with other agents using the chat tools.
|
| 50 |
+
Search is your speciality. You identify as "search_agent".
|
| 51 |
+
|
| 52 |
+
If you have no tasks yet, call the wait for mentions tool. Don't ask agents for tasks, wait for them to ask you.
|
| 53 |
+
{os.getenv("CORAL_PROMPT_SYSTEM", default = "")}
|
| 54 |
+
|
| 55 |
+
Here are the guidelines for using the communication tools:
|
| 56 |
+
{get_tools_description()}
|
| 57 |
+
"""
|
| 58 |
+
)
|
| 59 |
+
model = ModelFactory.create(
|
| 60 |
+
model_platform=ModelPlatformType[PLATFORM_TYPE],
|
| 61 |
+
model_type=ModelType[MODEL_TYPE],
|
| 62 |
+
api_key=os.getenv("API_KEY"),
|
| 63 |
+
model_config_dict=MODEL_CONFIG,
|
| 64 |
+
)
|
| 65 |
+
camel_agent = ChatAgent(
|
| 66 |
+
system_message=sys_msg,
|
| 67 |
+
model=model,
|
| 68 |
+
tools=tools,
|
| 69 |
+
message_window_size=MESSAGE_WINDOW_SIZE,
|
| 70 |
+
token_limit=TOKEN_LIMIT
|
| 71 |
+
)
|
| 72 |
+
return camel_agent
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
if __name__ == "__main__":
|
| 76 |
+
asyncio.run(main())
|
examples/camel-search-maths/prompts.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def get_tools_description():
|
| 2 |
+
return """
|
| 3 |
+
You have access to communication tools to interact with other agents.
|
| 4 |
+
|
| 5 |
+
Before using the tools, you need to register yourself using the register tool. Name yourself with a name that describes your speciality well. Do not be too generic. For example, if you are a search agent, you can name yourself "search_agent".
|
| 6 |
+
|
| 7 |
+
If there are no other agents, remember to re-list the agents periodically using the list tool.
|
| 8 |
+
|
| 9 |
+
You should know that the user can't see any messages you send, you are expected to be autonomous and respond to the user only when you have finished working with other agents, using tools specifically for that.
|
| 10 |
+
|
| 11 |
+
You can emit as many messages as you like before using that tool when you are finished or absolutely need user input. You are on a loop and will see a "user" message every 4 seconds, but it's not really from the user.
|
| 12 |
+
|
| 13 |
+
When sending messages, you MUST put the name of the agent(s) you are talking to in the mentions field of the send message tool. If you don't mention anybody, nobody will receive it!
|
| 14 |
+
|
| 15 |
+
Run the wait for mention tool when you are ready to receive a message from another agent. This is the preferred way to wait for messages from other agents.
|
| 16 |
+
|
| 17 |
+
You'll only see messages from other agents since you last called the wait for mention tool. Remember to call this periodically. Also call this when you're waiting with nothing to do.
|
| 18 |
+
|
| 19 |
+
Don't try to guess any numbers or facts, only use reliable sources. If you are unsure, ask other agents for help.
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
def get_user_message():
|
| 23 |
+
return "[automated] continue collaborating with other agents. make sure to mention agents you intend to communicate with"
|
examples/camel-search-maths/requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
requests==2.32.3
|
| 2 |
+
camel-ai==0.2.46
|
| 3 |
+
asyncio==3.4.3
|
examples/camel-search-maths/search/coral-agent.toml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[agent]
|
| 2 |
+
name = "search"
|
| 3 |
+
version = "0.0.1"
|
| 4 |
+
|
| 5 |
+
[options]
|
| 6 |
+
OPENAI_API_KEY = { type = "string", description = "OpenAI API Key" }
|
| 7 |
+
GOOGLE_API_KEY = { type = "string", description = "Google API Key" }
|
| 8 |
+
SEARCH_ENGINE_ID = { type = "string", description = "Google Search Engine ID" }
|
| 9 |
+
|
| 10 |
+
[runtimes.executable]
|
| 11 |
+
command = ["bash", "examples/camel-search-maths/venv.sh", "examples/camel-search-maths/mcp_example_camel_math.py"]
|
examples/camel-search-maths/tools.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
import requests
|
| 4 |
+
from camel.toolkits import BaseToolkit
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class JinaBrowsingToolkit(BaseToolkit):
|
| 8 |
+
def get_url_content(self, url: str) -> str:
|
| 9 |
+
r"""Fetch the content of a URL using the r.jina.ai service.
|
| 10 |
+
|
| 11 |
+
Args:
|
| 12 |
+
url (str): The URL to fetch content from.
|
| 13 |
+
|
| 14 |
+
Returns:
|
| 15 |
+
str: The markdown content of the URL.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
# Replace http with https and add https if not present
|
| 19 |
+
if not url.startswith("https://"):
|
| 20 |
+
url = "https://" + url.lstrip("https://").lstrip("http://")
|
| 21 |
+
|
| 22 |
+
jina_url = f"https://r.jina.ai/{url}"
|
| 23 |
+
headers = {}
|
| 24 |
+
if os.environ.get('JINA_PROXY_URL'):
|
| 25 |
+
headers['X-Proxy-Url'] = os.environ.get('JINA_PROXY_URL')
|
| 26 |
+
|
| 27 |
+
auth_token = os.environ.get('JINA_AUTH_TOKEN')
|
| 28 |
+
if auth_token:
|
| 29 |
+
headers['Authorization'] = f'Bearer {auth_token}'
|
| 30 |
+
try:
|
| 31 |
+
response = requests.get(jina_url, headers=headers)
|
| 32 |
+
response.raise_for_status()
|
| 33 |
+
return response.text
|
| 34 |
+
except requests.RequestException as e:
|
| 35 |
+
return f"Error fetching URL content: {e!s}"
|
| 36 |
+
|
| 37 |
+
def get_url_content_with_context(
|
| 38 |
+
self,
|
| 39 |
+
url: str,
|
| 40 |
+
search_string: str,
|
| 41 |
+
context_chars: int = 700,
|
| 42 |
+
max_instances: int = 3,
|
| 43 |
+
) -> str:
|
| 44 |
+
r"""Fetch the content of a URL and return context around all instances of a specific string.
|
| 45 |
+
|
| 46 |
+
Args:
|
| 47 |
+
url (str): The URL to fetch content from.
|
| 48 |
+
search_string (str): The string to search for in the content.
|
| 49 |
+
context_chars (int): Number of characters to return before and after each found string.
|
| 50 |
+
max_instances (int): Maximum number of instances to return.
|
| 51 |
+
|
| 52 |
+
Returns:
|
| 53 |
+
str: The context around all found instances of the string, or an error message if not found.
|
| 54 |
+
|
| 55 |
+
If there are no results, try again with a more likely search string. Start with a more likely string and only use a less likely string if the first one has too many results.
|
| 56 |
+
"""
|
| 57 |
+
content = self.get_url_content(url)
|
| 58 |
+
if content.startswith("Error fetching URL content"):
|
| 59 |
+
return content
|
| 60 |
+
|
| 61 |
+
instances = []
|
| 62 |
+
start = 0
|
| 63 |
+
while True:
|
| 64 |
+
index = content.lower().find(search_string.lower(), start)
|
| 65 |
+
if index == -1 or len(instances) >= max_instances:
|
| 66 |
+
break
|
| 67 |
+
|
| 68 |
+
context_start = max(0, index - context_chars)
|
| 69 |
+
context_end = min(
|
| 70 |
+
len(content), index + len(search_string) + context_chars
|
| 71 |
+
)
|
| 72 |
+
instance_context = content[context_start:context_end]
|
| 73 |
+
instances.append(
|
| 74 |
+
f"Instance {len(instances) + 1}:\n{instance_context}\n"
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
start = index + len(search_string)
|
| 78 |
+
|
| 79 |
+
if instances:
|
| 80 |
+
return (
|
| 81 |
+
f"Found {len(instances)} instance(s) of '{search_string}':\n\n"
|
| 82 |
+
+ '\n'.join(instances)
|
| 83 |
+
)
|
| 84 |
+
else:
|
| 85 |
+
return f"Search string '{search_string}' not found in the content."
|
examples/camel-search-maths/venv.sh
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
source examples/camel-search-maths/.venv/bin/activate
|
| 2 |
+
python -u "$1"
|
examples/session-posts/Local docker session.http
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
POST http://localhost:5555/sessions
|
| 2 |
+
Content-Type: application/json
|
| 3 |
+
|
| 4 |
+
{
|
| 5 |
+
"applicationId": "app",
|
| 6 |
+
"privacyKey": "priv",
|
| 7 |
+
"agentGraph": {
|
| 8 |
+
"agents": {
|
| 9 |
+
"my-deepresearch": {
|
| 10 |
+
"type": "local",
|
| 11 |
+
"agentType": "deepresearch",
|
| 12 |
+
"options": {
|
| 13 |
+
"OPENAI_API_KEY": "{{OPENAI_API_KEY}}",
|
| 14 |
+
"LINKUP_API_KEY": "{{LINKUP_API_KEY}}"
|
| 15 |
+
}
|
| 16 |
+
},
|
| 17 |
+
"my-repounderstanding": {
|
| 18 |
+
"type": "local",
|
| 19 |
+
"agentType": "repounderstanding",
|
| 20 |
+
"options": {
|
| 21 |
+
"OPENAI_API_KEY": "{{OPENAI_API_KEY}}",
|
| 22 |
+
"GITHUB_ACCESS_TOKEN": "{{GITHUB_ACCESS_TOKEN}}"
|
| 23 |
+
}
|
| 24 |
+
},
|
| 25 |
+
"my-interface": {
|
| 26 |
+
"type": "local",
|
| 27 |
+
"agentType": "interface",
|
| 28 |
+
"options": {
|
| 29 |
+
"OPENAI_API_KEY": "{{OPENAI_API_KEY}}",
|
| 30 |
+
"HUMAN_RESPONSE": "Please give me a comprehensive instruction of the master branch of Coral-Protocol/coral-server."
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
},
|
| 34 |
+
"links": [
|
| 35 |
+
["my-repounderstanding", "my-deepresearch", "my-interface"]
|
| 36 |
+
]
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
###
|
examples/session-posts/application.yaml
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Default application configuration
|
| 2 |
+
# TODO: Applications are a work in progress. This is safe to ignore for now.
|
| 3 |
+
applications:
|
| 4 |
+
- id: "app"
|
| 5 |
+
name: "Default Application"
|
| 6 |
+
description: "Default application for testing"
|
| 7 |
+
privacyKeys:
|
| 8 |
+
- "default-key"
|
| 9 |
+
- "public"
|
| 10 |
+
- "priv"
|
| 11 |
+
|
| 12 |
+
# NOTE: this will almost certainly *not* work on your machine without some tweaking of the `command`'s for each agent
|
| 13 |
+
|
| 14 |
+
# Registry of agents we can orchestrate
|
| 15 |
+
registry:
|
| 16 |
+
# test:
|
| 17 |
+
# options:
|
| 18 |
+
# - name: "NAME"
|
| 19 |
+
# type: "string"
|
| 20 |
+
# description: "Test agent name"
|
| 21 |
+
# runtime:
|
| 22 |
+
# type: "executable"
|
| 23 |
+
# command: ["bash", "examples/camel-search-maths/venv.sh", "examples/camel-search-maths/test.py"]
|
| 24 |
+
# environment:
|
| 25 |
+
# - option: "NAME"
|
| 26 |
+
repounderstanding:
|
| 27 |
+
# Exposed configuration for consumers of this agent
|
| 28 |
+
options:
|
| 29 |
+
- name: "OPENAI_API_KEY"
|
| 30 |
+
type: "string"
|
| 31 |
+
description: "OpenAI API Key"
|
| 32 |
+
- name: "GITHUB_ACCESS_TOKEN"
|
| 33 |
+
type: "string"
|
| 34 |
+
description: "GitHub Access Token"
|
| 35 |
+
|
| 36 |
+
# How this agent is actually orchestrated locally
|
| 37 |
+
runtime:
|
| 38 |
+
type: "docker"
|
| 39 |
+
environment:
|
| 40 |
+
- name: "API_KEY"
|
| 41 |
+
from: "OPENAI_API_KEY"
|
| 42 |
+
- name: "GITHUB_ACCESS_TOKEN"
|
| 43 |
+
from: "GITHUB_ACCESS_TOKEN"
|
| 44 |
+
image: "sd2879/coral-repounderstanding:latest"
|
| 45 |
+
|
| 46 |
+
deepresearch:
|
| 47 |
+
options:
|
| 48 |
+
- name: "OPENAI_API_KEY"
|
| 49 |
+
type: "string"
|
| 50 |
+
description: "OpenAI API Key"
|
| 51 |
+
- name: "LINKUP_API_KEY"
|
| 52 |
+
type: "string"
|
| 53 |
+
description: "LinkUp API Key. Get from https://linkup.so/"
|
| 54 |
+
|
| 55 |
+
runtime:
|
| 56 |
+
type: "docker"
|
| 57 |
+
environment:
|
| 58 |
+
- name: "API_KEY"
|
| 59 |
+
from: "OPENAI_API_KEY"
|
| 60 |
+
image: "sd2879/coral-opendeepresearch:latest"
|
| 61 |
+
|
| 62 |
+
interface:
|
| 63 |
+
options:
|
| 64 |
+
- name: "OPENAI_API_KEY"
|
| 65 |
+
type: "string"
|
| 66 |
+
description: "OpenAI API Key"
|
| 67 |
+
- name: "HUMAN_RESPONSE"
|
| 68 |
+
type: "string"
|
| 69 |
+
description: "Human response to be used in the interface agent"
|
| 70 |
+
|
| 71 |
+
runtime:
|
| 72 |
+
type: "docker"
|
| 73 |
+
image: "sd2879/coral-interface-agent:latest"
|
| 74 |
+
environment:
|
| 75 |
+
- name: "API_KEY"
|
| 76 |
+
from: "OPENAI_API_KEY"
|
| 77 |
+
- name: "HUMAN_RESPONSE"
|
| 78 |
+
from: "HUMAN_RESPONSE"
|
| 79 |
+
|
| 80 |
+
# Uncomment to configure an external application source
|
| 81 |
+
# applicationSource:
|
| 82 |
+
# type: "http"
|
| 83 |
+
# url: "https://example.com/applications"
|
| 84 |
+
# refreshIntervalSeconds: 3600
|
gradle.properties
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kotlin.code.style=official
|
| 2 |
+
org.gradle.console=plain
|
gradle/wrapper/gradle-wrapper.jar
ADDED
|
Binary file (60.8 kB). View file
|
|
|
gradle/wrapper/gradle-wrapper.properties
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#Fri Mar 21 11:39:48 GMT 2025
|
| 2 |
+
distributionBase=GRADLE_USER_HOME
|
| 3 |
+
distributionPath=wrapper/dists
|
| 4 |
+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
|
| 5 |
+
zipStoreBase=GRADLE_USER_HOME
|
| 6 |
+
zipStorePath=wrapper/dists
|
| 7 |
+
org.gradle.java.installations.fromEnv=JAVA_HOME
|
| 8 |
+
org.gradle.java.installations.auto-download=true
|
gradlew
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
|
| 3 |
+
#
|
| 4 |
+
# Copyright © 2015-2021 the original authors.
|
| 5 |
+
#
|
| 6 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
+
# you may not use this file except in compliance with the License.
|
| 8 |
+
# You may obtain a copy of the License at
|
| 9 |
+
#
|
| 10 |
+
# https://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
#
|
| 12 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
# See the License for the specific language governing permissions and
|
| 16 |
+
# limitations under the License.
|
| 17 |
+
#
|
| 18 |
+
|
| 19 |
+
##############################################################################
|
| 20 |
+
#
|
| 21 |
+
# Gradle start up script for POSIX generated by Gradle.
|
| 22 |
+
#
|
| 23 |
+
# Important for running:
|
| 24 |
+
#
|
| 25 |
+
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
| 26 |
+
# noncompliant, but you have some other compliant shell such as ksh or
|
| 27 |
+
# bash, then to run this script, type that shell name before the whole
|
| 28 |
+
# command line, like:
|
| 29 |
+
#
|
| 30 |
+
# ksh Gradle
|
| 31 |
+
#
|
| 32 |
+
# Busybox and similar reduced shells will NOT work, because this script
|
| 33 |
+
# requires all of these POSIX shell features:
|
| 34 |
+
# * functions;
|
| 35 |
+
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
| 36 |
+
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
| 37 |
+
# * compound commands having a testable exit status, especially «case»;
|
| 38 |
+
# * various built-in commands including «command», «set», and «ulimit».
|
| 39 |
+
#
|
| 40 |
+
# Important for patching:
|
| 41 |
+
#
|
| 42 |
+
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
| 43 |
+
# by Bash, Ksh, etc; in particular arrays are avoided.
|
| 44 |
+
#
|
| 45 |
+
# The "traditional" practice of packing multiple parameters into a
|
| 46 |
+
# space-separated string is a well documented source of bugs and security
|
| 47 |
+
# problems, so this is (mostly) avoided, by progressively accumulating
|
| 48 |
+
# options in "$@", and eventually passing that to Java.
|
| 49 |
+
#
|
| 50 |
+
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
| 51 |
+
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
| 52 |
+
# see the in-line comments for details.
|
| 53 |
+
#
|
| 54 |
+
# There are tweaks for specific operating systems such as AIX, CygWin,
|
| 55 |
+
# Darwin, MinGW, and NonStop.
|
| 56 |
+
#
|
| 57 |
+
# (3) This script is generated from the Groovy template
|
| 58 |
+
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
| 59 |
+
# within the Gradle project.
|
| 60 |
+
#
|
| 61 |
+
# You can find Gradle at https://github.com/gradle/gradle/.
|
| 62 |
+
#
|
| 63 |
+
##############################################################################
|
| 64 |
+
|
| 65 |
+
# Attempt to set APP_HOME
|
| 66 |
+
|
| 67 |
+
# Resolve links: $0 may be a link
|
| 68 |
+
app_path=$0
|
| 69 |
+
|
| 70 |
+
# Need this for daisy-chained symlinks.
|
| 71 |
+
while
|
| 72 |
+
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
| 73 |
+
[ -h "$app_path" ]
|
| 74 |
+
do
|
| 75 |
+
ls=$( ls -ld "$app_path" )
|
| 76 |
+
link=${ls#*' -> '}
|
| 77 |
+
case $link in #(
|
| 78 |
+
/*) app_path=$link ;; #(
|
| 79 |
+
*) app_path=$APP_HOME$link ;;
|
| 80 |
+
esac
|
| 81 |
+
done
|
| 82 |
+
|
| 83 |
+
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
| 84 |
+
|
| 85 |
+
APP_NAME="Gradle"
|
| 86 |
+
APP_BASE_NAME=${0##*/}
|
| 87 |
+
|
| 88 |
+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
| 89 |
+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
| 90 |
+
|
| 91 |
+
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
| 92 |
+
MAX_FD=maximum
|
| 93 |
+
|
| 94 |
+
warn () {
|
| 95 |
+
echo "$*"
|
| 96 |
+
} >&2
|
| 97 |
+
|
| 98 |
+
die () {
|
| 99 |
+
echo
|
| 100 |
+
echo "$*"
|
| 101 |
+
echo
|
| 102 |
+
exit 1
|
| 103 |
+
} >&2
|
| 104 |
+
|
| 105 |
+
# OS specific support (must be 'true' or 'false').
|
| 106 |
+
cygwin=false
|
| 107 |
+
msys=false
|
| 108 |
+
darwin=false
|
| 109 |
+
nonstop=false
|
| 110 |
+
case "$( uname )" in #(
|
| 111 |
+
CYGWIN* ) cygwin=true ;; #(
|
| 112 |
+
Darwin* ) darwin=true ;; #(
|
| 113 |
+
MSYS* | MINGW* ) msys=true ;; #(
|
| 114 |
+
NONSTOP* ) nonstop=true ;;
|
| 115 |
+
esac
|
| 116 |
+
|
| 117 |
+
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
# Determine the Java command to use to start the JVM.
|
| 121 |
+
if [ -n "$JAVA_HOME" ] ; then
|
| 122 |
+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
| 123 |
+
# IBM's JDK on AIX uses strange locations for the executables
|
| 124 |
+
JAVACMD=$JAVA_HOME/jre/sh/java
|
| 125 |
+
else
|
| 126 |
+
JAVACMD=$JAVA_HOME/bin/java
|
| 127 |
+
fi
|
| 128 |
+
if [ ! -x "$JAVACMD" ] ; then
|
| 129 |
+
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
| 130 |
+
|
| 131 |
+
Please set the JAVA_HOME variable in your environment to match the
|
| 132 |
+
location of your Java installation."
|
| 133 |
+
fi
|
| 134 |
+
else
|
| 135 |
+
JAVACMD=java
|
| 136 |
+
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
| 137 |
+
|
| 138 |
+
Please set the JAVA_HOME variable in your environment to match the
|
| 139 |
+
location of your Java installation."
|
| 140 |
+
fi
|
| 141 |
+
|
| 142 |
+
# Increase the maximum file descriptors if we can.
|
| 143 |
+
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
| 144 |
+
case $MAX_FD in #(
|
| 145 |
+
max*)
|
| 146 |
+
MAX_FD=$( ulimit -H -n ) ||
|
| 147 |
+
warn "Could not query maximum file descriptor limit"
|
| 148 |
+
esac
|
| 149 |
+
case $MAX_FD in #(
|
| 150 |
+
'' | soft) :;; #(
|
| 151 |
+
*)
|
| 152 |
+
ulimit -n "$MAX_FD" ||
|
| 153 |
+
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
| 154 |
+
esac
|
| 155 |
+
fi
|
| 156 |
+
|
| 157 |
+
# Collect all arguments for the java command, stacking in reverse order:
|
| 158 |
+
# * args from the command line
|
| 159 |
+
# * the main class name
|
| 160 |
+
# * -classpath
|
| 161 |
+
# * -D...appname settings
|
| 162 |
+
# * --module-path (only if needed)
|
| 163 |
+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
| 164 |
+
|
| 165 |
+
# For Cygwin or MSYS, switch paths to Windows format before running java
|
| 166 |
+
if "$cygwin" || "$msys" ; then
|
| 167 |
+
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
| 168 |
+
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
| 169 |
+
|
| 170 |
+
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
| 171 |
+
|
| 172 |
+
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
| 173 |
+
for arg do
|
| 174 |
+
if
|
| 175 |
+
case $arg in #(
|
| 176 |
+
-*) false ;; # don't mess with options #(
|
| 177 |
+
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
| 178 |
+
[ -e "$t" ] ;; #(
|
| 179 |
+
*) false ;;
|
| 180 |
+
esac
|
| 181 |
+
then
|
| 182 |
+
arg=$( cygpath --path --ignore --mixed "$arg" )
|
| 183 |
+
fi
|
| 184 |
+
# Roll the args list around exactly as many times as the number of
|
| 185 |
+
# args, so each arg winds up back in the position where it started, but
|
| 186 |
+
# possibly modified.
|
| 187 |
+
#
|
| 188 |
+
# NB: a `for` loop captures its iteration list before it begins, so
|
| 189 |
+
# changing the positional parameters here affects neither the number of
|
| 190 |
+
# iterations, nor the values presented in `arg`.
|
| 191 |
+
shift # remove old arg
|
| 192 |
+
set -- "$@" "$arg" # push replacement arg
|
| 193 |
+
done
|
| 194 |
+
fi
|
| 195 |
+
|
| 196 |
+
# Collect all arguments for the java command;
|
| 197 |
+
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
| 198 |
+
# shell script including quotes and variable substitutions, so put them in
|
| 199 |
+
# double quotes to make sure that they get re-expanded; and
|
| 200 |
+
# * put everything else in single quotes, so that it's not re-expanded.
|
| 201 |
+
|
| 202 |
+
set -- \
|
| 203 |
+
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
| 204 |
+
-classpath "$CLASSPATH" \
|
| 205 |
+
org.gradle.wrapper.GradleWrapperMain \
|
| 206 |
+
"$@"
|
| 207 |
+
|
| 208 |
+
# Use "xargs" to parse quoted args.
|
| 209 |
+
#
|
| 210 |
+
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
| 211 |
+
#
|
| 212 |
+
# In Bash we could simply go:
|
| 213 |
+
#
|
| 214 |
+
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
| 215 |
+
# set -- "${ARGS[@]}" "$@"
|
| 216 |
+
#
|
| 217 |
+
# but POSIX shell has neither arrays nor command substitution, so instead we
|
| 218 |
+
# post-process each arg (as a line of input to sed) to backslash-escape any
|
| 219 |
+
# character that might be a shell metacharacter, then use eval to reverse
|
| 220 |
+
# that process (while maintaining the separation between arguments), and wrap
|
| 221 |
+
# the whole thing up as a single "set" statement.
|
| 222 |
+
#
|
| 223 |
+
# This will of course break if any of these variables contains a newline or
|
| 224 |
+
# an unmatched quote.
|
| 225 |
+
#
|
| 226 |
+
|
| 227 |
+
eval "set -- $(
|
| 228 |
+
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
| 229 |
+
xargs -n1 |
|
| 230 |
+
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
| 231 |
+
tr '\n' ' '
|
| 232 |
+
)" '"$@"'
|
| 233 |
+
|
| 234 |
+
exec "$JAVACMD" "$@"
|
gradlew.bat
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@rem
|
| 2 |
+
@rem Copyright 2015 the original author or authors.
|
| 3 |
+
@rem
|
| 4 |
+
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
@rem you may not use this file except in compliance with the License.
|
| 6 |
+
@rem You may obtain a copy of the License at
|
| 7 |
+
@rem
|
| 8 |
+
@rem https://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
@rem
|
| 10 |
+
@rem Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
@rem See the License for the specific language governing permissions and
|
| 14 |
+
@rem limitations under the License.
|
| 15 |
+
@rem
|
| 16 |
+
|
| 17 |
+
@if "%DEBUG%" == "" @echo off
|
| 18 |
+
@rem ##########################################################################
|
| 19 |
+
@rem
|
| 20 |
+
@rem Gradle startup script for Windows
|
| 21 |
+
@rem
|
| 22 |
+
@rem ##########################################################################
|
| 23 |
+
|
| 24 |
+
@rem Set local scope for the variables with windows NT shell
|
| 25 |
+
if "%OS%"=="Windows_NT" setlocal
|
| 26 |
+
|
| 27 |
+
set DIRNAME=%~dp0
|
| 28 |
+
if "%DIRNAME%" == "" set DIRNAME=.
|
| 29 |
+
set APP_BASE_NAME=%~n0
|
| 30 |
+
set APP_HOME=%DIRNAME%
|
| 31 |
+
|
| 32 |
+
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
| 33 |
+
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
| 34 |
+
|
| 35 |
+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
| 36 |
+
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
| 37 |
+
|
| 38 |
+
@rem Find java.exe
|
| 39 |
+
if defined JAVA_HOME goto findJavaFromJavaHome
|
| 40 |
+
|
| 41 |
+
set JAVA_EXE=java.exe
|
| 42 |
+
%JAVA_EXE% -version >NUL 2>&1
|
| 43 |
+
if "%ERRORLEVEL%" == "0" goto execute
|
| 44 |
+
|
| 45 |
+
echo.
|
| 46 |
+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
| 47 |
+
echo.
|
| 48 |
+
echo Please set the JAVA_HOME variable in your environment to match the
|
| 49 |
+
echo location of your Java installation.
|
| 50 |
+
|
| 51 |
+
goto fail
|
| 52 |
+
|
| 53 |
+
:findJavaFromJavaHome
|
| 54 |
+
set JAVA_HOME=%JAVA_HOME:"=%
|
| 55 |
+
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
| 56 |
+
|
| 57 |
+
if exist "%JAVA_EXE%" goto execute
|
| 58 |
+
|
| 59 |
+
echo.
|
| 60 |
+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
| 61 |
+
echo.
|
| 62 |
+
echo Please set the JAVA_HOME variable in your environment to match the
|
| 63 |
+
echo location of your Java installation.
|
| 64 |
+
|
| 65 |
+
goto fail
|
| 66 |
+
|
| 67 |
+
:execute
|
| 68 |
+
@rem Setup the command line
|
| 69 |
+
|
| 70 |
+
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
@rem Execute Gradle
|
| 74 |
+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
| 75 |
+
|
| 76 |
+
:end
|
| 77 |
+
@rem End local scope for the variables with windows NT shell
|
| 78 |
+
if "%ERRORLEVEL%"=="0" goto mainEnd
|
| 79 |
+
|
| 80 |
+
:fail
|
| 81 |
+
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
| 82 |
+
rem the _cmd.exe /c_ return code!
|
| 83 |
+
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
| 84 |
+
exit /b 1
|
| 85 |
+
|
| 86 |
+
:mainEnd
|
| 87 |
+
if "%OS%"=="Windows_NT" endlocal
|
| 88 |
+
|
| 89 |
+
:omega
|
images/thumnail2.png
ADDED
|
Git LFS Details
|
settings.gradle.kts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
plugins {
|
| 2 |
+
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
|
| 3 |
+
}
|
| 4 |
+
rootProject.name = "coral-server"
|
| 5 |
+
|
src/main/kotlin/org/coralprotocol/coralserver/EventBus.kt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package org.coralprotocol.coralserver
|
| 2 |
+
|
| 3 |
+
import kotlinx.coroutines.flow.MutableSharedFlow
|
| 4 |
+
import kotlinx.coroutines.flow.asSharedFlow
|
| 5 |
+
|
| 6 |
+
class EventBus<E>(val replay: Int = 0) {
|
| 7 |
+
private val _events = MutableSharedFlow<E>(extraBufferCapacity = 1024, replay = replay) // private mutable shared flow
|
| 8 |
+
val events = _events.asSharedFlow() // publicly exposed as read-only shared flow
|
| 9 |
+
|
| 10 |
+
fun emit(event: E) {
|
| 11 |
+
_events.tryEmit(event) // suspends until all subscribers receive it
|
| 12 |
+
}
|
| 13 |
+
}
|
src/main/kotlin/org/coralprotocol/coralserver/IterHelpers.kt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package org.coralprotocol.coralserver
|
| 2 |
+
|
| 3 |
+
fun <K, V> List<Pair<K, V>>.toMapOnDuplicate(onDuplicates: (duplicates: List<K>) -> Unit): Map<K, V> {
|
| 4 |
+
val groups: Map<K, List<Pair<K, V>>> = groupBy { it.first }
|
| 5 |
+
val duplicates = groups.filter { it.value.size > 1 }.map { it.key }
|
| 6 |
+
if (duplicates.isNotEmpty()) {
|
| 7 |
+
onDuplicates(duplicates)
|
| 8 |
+
}
|
| 9 |
+
return groups.mapValues { it.value.first().second }
|
| 10 |
+
}
|
src/main/kotlin/org/coralprotocol/coralserver/Main.kt
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package org.coralprotocol.coralserver
|
| 2 |
+
|
| 3 |
+
import io.github.oshai.kotlinlogging.KotlinLogging
|
| 4 |
+
import kotlinx.coroutines.runBlocking
|
| 5 |
+
import org.coralprotocol.coralserver.config.ConfigCollection
|
| 6 |
+
import org.coralprotocol.coralserver.agent.runtime.Orchestrator
|
| 7 |
+
import org.coralprotocol.coralserver.server.CoralServer
|
| 8 |
+
import org.coralprotocol.coralserver.session.SessionManager
|
| 9 |
+
|
| 10 |
+
private val logger = KotlinLogging.logger {}
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* Start sse-server mcp on port 5555.
|
| 14 |
+
*
|
| 15 |
+
* @param args
|
| 16 |
+
* - "--stdio": Runs an MCP server using standard input/output.
|
| 17 |
+
* - "--sse-server <port>": Runs an SSE MCP server with a plain configuration.
|
| 18 |
+
* - "--dev": Runs the server in development mode.
|
| 19 |
+
*/
|
| 20 |
+
fun main(args: Array<String>) {
|
| 21 |
+
// System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "TRACE");
|
| 22 |
+
// System.setProperty("io.ktor.development", "true")
|
| 23 |
+
|
| 24 |
+
val command = args.firstOrNull() ?: "--sse-server"
|
| 25 |
+
val port = args.getOrNull(1)?.toUShortOrNull() ?: 5555u
|
| 26 |
+
val devMode = args.contains("--dev")
|
| 27 |
+
|
| 28 |
+
when (command) {
|
| 29 |
+
// "--stdio" -> runMcpServerUsingStdio()
|
| 30 |
+
"--sse-server" -> {
|
| 31 |
+
val appConfig = ConfigCollection()
|
| 32 |
+
|
| 33 |
+
val orchestrator = Orchestrator(appConfig)
|
| 34 |
+
val server = CoralServer(
|
| 35 |
+
port = port,
|
| 36 |
+
devmode = devMode,
|
| 37 |
+
appConfig = appConfig,
|
| 38 |
+
sessionManager = SessionManager(orchestrator, port = port)
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
// Add shutdown hook to stop the server gracefully
|
| 42 |
+
Runtime.getRuntime().addShutdownHook(Thread {
|
| 43 |
+
logger.info { "Shutting down server..." }
|
| 44 |
+
appConfig.stopWatch()
|
| 45 |
+
server.stop()
|
| 46 |
+
runBlocking {
|
| 47 |
+
orchestrator.destroy()
|
| 48 |
+
}
|
| 49 |
+
})
|
| 50 |
+
|
| 51 |
+
server.start(wait = true)
|
| 52 |
+
}
|
| 53 |
+
else -> {
|
| 54 |
+
logger.error { "Unknown command: $command" }
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
}
|
src/main/kotlin/org/coralprotocol/coralserver/agent/graph/GraphAgent.kt
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package org.coralprotocol.coralserver.agent.graph
|
| 2 |
+
|
| 3 |
+
import io.github.smiley4.schemakenerator.core.annotations.Description
|
| 4 |
+
import kotlinx.serialization.SerialName
|
| 5 |
+
import kotlinx.serialization.Serializable
|
| 6 |
+
import org.coralprotocol.coralserver.agent.registry.AgentOptionValue
|
| 7 |
+
import org.coralprotocol.coralserver.session.CustomTool
|
| 8 |
+
|
| 9 |
+
@Serializable
|
| 10 |
+
@Description("The representation of an agent on the agent graph. This refers to a registry agent by name")
|
| 11 |
+
data class GraphAgent(
|
| 12 |
+
@Description("The name of the agent in the registry")
|
| 13 |
+
val name: String,
|
| 14 |
+
|
| 15 |
+
@Description("The options that are passed to the agent")
|
| 16 |
+
val options: Map<String, AgentOptionValue>,
|
| 17 |
+
|
| 18 |
+
@Description("The system prompt/developer text/preamble passed to the agent")
|
| 19 |
+
val systemPrompt: String?,
|
| 20 |
+
|
| 21 |
+
@Description("<todo description>")
|
| 22 |
+
val extraTools: Set<String>,
|
| 23 |
+
|
| 24 |
+
@Description("<todo description>")
|
| 25 |
+
val blocking: Boolean,
|
| 26 |
+
|
| 27 |
+
@Description("The provider for this agent")
|
| 28 |
+
val provider: GraphAgentProvider
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
@Serializable
|
| 32 |
+
@Description("A graph of agents, tools and links between them. The agent links define agent groups")
|
| 33 |
+
data class AgentGraph(
|
| 34 |
+
@Description("A map of agent names to graph agents")
|
| 35 |
+
val agents: Map<String, GraphAgent>,
|
| 36 |
+
|
| 37 |
+
@Description("<todo description>")
|
| 38 |
+
val tools: Map<String, CustomTool>,
|
| 39 |
+
|
| 40 |
+
@Description("<todo description>")
|
| 41 |
+
val links: Set<Set<String>>,
|
| 42 |
+
)
|
| 43 |
+
|
src/main/kotlin/org/coralprotocol/coralserver/agent/graph/GraphAgentProvider.kt
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@file:OptIn(ExperimentalSerializationApi::class)
|
| 2 |
+
|
| 3 |
+
package org.coralprotocol.coralserver.agent.graph
|
| 4 |
+
|
| 5 |
+
import io.github.smiley4.schemakenerator.core.annotations.Description
|
| 6 |
+
import kotlinx.serialization.ExperimentalSerializationApi
|
| 7 |
+
import kotlinx.serialization.SerialName
|
| 8 |
+
import kotlinx.serialization.Serializable
|
| 9 |
+
import kotlinx.serialization.json.JsonClassDiscriminator
|
| 10 |
+
import org.coralprotocol.coralserver.agent.runtime.RuntimeId
|
| 11 |
+
|
| 12 |
+
@Serializable
|
| 13 |
+
@JsonClassDiscriminator("type")
|
| 14 |
+
@Description("A local or remote provider for an agent")
|
| 15 |
+
sealed class GraphAgentProvider {
|
| 16 |
+
@Serializable
|
| 17 |
+
@SerialName("local")
|
| 18 |
+
@Description("The agent will be provided by this server")
|
| 19 |
+
data class Local(
|
| 20 |
+
val runtime: RuntimeId,
|
| 21 |
+
) : GraphAgentProvider()
|
| 22 |
+
|
| 23 |
+
@Serializable
|
| 24 |
+
@SerialName("remote")
|
| 25 |
+
@Description("Agent will be provided by another Coral server")
|
| 26 |
+
data class Remote(
|
| 27 |
+
@Description("The runtime that should be used for this remote agent. Servers can export only specific runtimes so the runtime choice may narrow servers that can adequately provide the agent")
|
| 28 |
+
val runtime: RuntimeId,
|
| 29 |
+
|
| 30 |
+
@Description("A description of which servers should be queried for this remote agent request")
|
| 31 |
+
val serverSource: GraphAgentServerSource,
|
| 32 |
+
|
| 33 |
+
@Description("Customisation for the scoring of servers")
|
| 34 |
+
val serverScoring: GraphAgentServerScoring? = GraphAgentServerScoring.Default()
|
| 35 |
+
) : GraphAgentProvider()
|
| 36 |
+
}
|
src/main/kotlin/org/coralprotocol/coralserver/agent/graph/GraphAgentRequest.kt
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package org.coralprotocol.coralserver.agent.graph
|
| 2 |
+
|
| 3 |
+
import io.github.smiley4.schemakenerator.core.annotations.Description
|
| 4 |
+
import kotlinx.serialization.Serializable
|
| 5 |
+
import org.coralprotocol.coralserver.agent.registry.AgentOptionValue
|
| 6 |
+
|
| 7 |
+
@Serializable
|
| 8 |
+
@Description("A request for an agent")
|
| 9 |
+
data class GraphAgentRequest(
|
| 10 |
+
@Description("The name of the agent to run, this must match the name of the agent in the registry")
|
| 11 |
+
val agentName: String,
|
| 12 |
+
|
| 13 |
+
@Description("The arguments to pass to the agent")
|
| 14 |
+
val options: Map<String, AgentOptionValue>,
|
| 15 |
+
|
| 16 |
+
@Description("The system prompt/developer text/preamble passed to the agent")
|
| 17 |
+
val systemPrompt: String?,
|
| 18 |
+
|
| 19 |
+
@Description("<todo description>")
|
| 20 |
+
val blocking: Boolean?,
|
| 21 |
+
|
| 22 |
+
@Description("<todo description>")
|
| 23 |
+
val tools: Set<String>,
|
| 24 |
+
|
| 25 |
+
@Description("The server that should provide this agent and the runtime to use")
|
| 26 |
+
val provider: GraphAgentProvider
|
| 27 |
+
)
|
src/main/kotlin/org/coralprotocol/coralserver/agent/graph/GraphAgentServer.kt
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@file:OptIn(ExperimentalSerializationApi::class)
|
| 2 |
+
|
| 3 |
+
package org.coralprotocol.coralserver.agent.graph
|
| 4 |
+
|
| 5 |
+
import kotlinx.serialization.ExperimentalSerializationApi
|
| 6 |
+
import kotlinx.serialization.SerialName
|
| 7 |
+
import kotlinx.serialization.Serializable
|
| 8 |
+
import kotlinx.serialization.json.JsonClassDiscriminator
|
| 9 |
+
|
| 10 |
+
@Serializable
|
| 11 |
+
data class GraphAgentServer(
|
| 12 |
+
val address: String,
|
| 13 |
+
val attributes: List<GraphAgentServerAttribute>
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
@Serializable
|
| 17 |
+
enum class GraphAgentServerAttributeType {
|
| 18 |
+
// possibly represented as a timezone
|
| 19 |
+
@SerialName("geographic_location")
|
| 20 |
+
GEOGRAPHIC_LOCATION,
|
| 21 |
+
|
| 22 |
+
// wallet ID?
|
| 23 |
+
@SerialName("attested_by")
|
| 24 |
+
ATTESTED_BY,
|
| 25 |
+
|
| 26 |
+
// todo: fill this out
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
@Serializable
|
| 30 |
+
@JsonClassDiscriminator("format")
|
| 31 |
+
sealed class GraphAgentServerAttribute() {
|
| 32 |
+
abstract val type: GraphAgentServerAttributeType
|
| 33 |
+
|
| 34 |
+
@Serializable
|
| 35 |
+
@SerialName("string")
|
| 36 |
+
data class String(
|
| 37 |
+
override val type: GraphAgentServerAttributeType,
|
| 38 |
+
val value: kotlin.String
|
| 39 |
+
) : GraphAgentServerAttribute()
|
| 40 |
+
|
| 41 |
+
@Serializable
|
| 42 |
+
@SerialName("number")
|
| 43 |
+
data class Number(
|
| 44 |
+
override val type: GraphAgentServerAttributeType,
|
| 45 |
+
val value: Double
|
| 46 |
+
) : GraphAgentServerAttribute()
|
| 47 |
+
|
| 48 |
+
@Serializable
|
| 49 |
+
@SerialName("boolean")
|
| 50 |
+
data class Boolean(
|
| 51 |
+
override val type: GraphAgentServerAttributeType,
|
| 52 |
+
val value: kotlin.Boolean
|
| 53 |
+
) : GraphAgentServerAttribute()
|
| 54 |
+
}
|
src/main/kotlin/org/coralprotocol/coralserver/agent/graph/GraphAgentServerScoring.kt
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@file:OptIn(ExperimentalSerializationApi::class)
|
| 2 |
+
|
| 3 |
+
package org.coralprotocol.coralserver.agent.graph
|
| 4 |
+
|
| 5 |
+
import io.github.smiley4.schemakenerator.core.annotations.Description
|
| 6 |
+
import kotlinx.serialization.ExperimentalSerializationApi
|
| 7 |
+
import kotlinx.serialization.SerialName
|
| 8 |
+
import kotlinx.serialization.Serializable
|
| 9 |
+
import kotlinx.serialization.json.JsonClassDiscriminator
|
| 10 |
+
|
| 11 |
+
@Serializable
|
| 12 |
+
sealed class GraphAgentServerScorerEffect {
|
| 13 |
+
@Serializable
|
| 14 |
+
@SerialName("flat")
|
| 15 |
+
@Description("A flat negative or positive weight")
|
| 16 |
+
data class Flat(val weight: Double) : GraphAgentServerScorerEffect()
|
| 17 |
+
|
| 18 |
+
@Serializable
|
| 19 |
+
@SerialName("multiplier")
|
| 20 |
+
@Description("A multiplier weight, this effect will only multiply against attributes with a number type")
|
| 21 |
+
data class Multiplier(val weight: Double) : GraphAgentServerScorerEffect()
|
| 22 |
+
|
| 23 |
+
fun apply(value: Double = 0.0): Double {
|
| 24 |
+
return when (this) {
|
| 25 |
+
is Flat -> {
|
| 26 |
+
weight
|
| 27 |
+
}
|
| 28 |
+
is Multiplier -> {
|
| 29 |
+
value * weight
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
@Serializable
|
| 36 |
+
@JsonClassDiscriminator("op")
|
| 37 |
+
sealed class GraphAgentServerCustomScorer {
|
| 38 |
+
@Serializable
|
| 39 |
+
@SerialName("is_true")
|
| 40 |
+
@Description("The effect will be applied for every attribute of the specified type with a boolean true value")
|
| 41 |
+
data class IsTrue(
|
| 42 |
+
val type: GraphAgentServerAttributeType,
|
| 43 |
+
val effect: GraphAgentServerScorerEffect.Flat
|
| 44 |
+
) : GraphAgentServerCustomScorer()
|
| 45 |
+
|
| 46 |
+
@Serializable
|
| 47 |
+
@SerialName("is_false")
|
| 48 |
+
@Description("The effect will be applied for every attribute of the specified type with a boolean false value")
|
| 49 |
+
data class IsFalse(
|
| 50 |
+
val type: GraphAgentServerAttributeType,
|
| 51 |
+
val effect: GraphAgentServerScorerEffect.Flat
|
| 52 |
+
) : GraphAgentServerCustomScorer()
|
| 53 |
+
|
| 54 |
+
@Serializable
|
| 55 |
+
@SerialName("is_present")
|
| 56 |
+
@Description("The effect will be applied for every attribute of the specified type")
|
| 57 |
+
data class IsPresent(
|
| 58 |
+
val type: GraphAgentServerAttributeType,
|
| 59 |
+
val effect: GraphAgentServerScorerEffect
|
| 60 |
+
) : GraphAgentServerCustomScorer()
|
| 61 |
+
|
| 62 |
+
@Serializable
|
| 63 |
+
@SerialName("is_not_present")
|
| 64 |
+
@Description("The effect will be applied if the no attribute of the specified type is present")
|
| 65 |
+
data class IsNotPresent(
|
| 66 |
+
val type: GraphAgentServerAttributeType,
|
| 67 |
+
val effect: GraphAgentServerScorerEffect.Flat
|
| 68 |
+
) : GraphAgentServerCustomScorer()
|
| 69 |
+
|
| 70 |
+
@Serializable
|
| 71 |
+
@SerialName("string_equal")
|
| 72 |
+
@Description("The effect will be applied for every attribute of the specified type with a matching string value")
|
| 73 |
+
data class StringEqual(
|
| 74 |
+
val type: GraphAgentServerAttributeType,
|
| 75 |
+
val string: String,
|
| 76 |
+
val effect: GraphAgentServerScorerEffect.Flat
|
| 77 |
+
) : GraphAgentServerCustomScorer()
|
| 78 |
+
|
| 79 |
+
@Serializable
|
| 80 |
+
@SerialName("string_not_equal")
|
| 81 |
+
@Description("The effect will be applied for every attribute of the specified type with a non-matching string value")
|
| 82 |
+
data class StringNotEqual(
|
| 83 |
+
val type: GraphAgentServerAttributeType,
|
| 84 |
+
val string: String,
|
| 85 |
+
val effect: GraphAgentServerScorerEffect.Flat
|
| 86 |
+
) : GraphAgentServerCustomScorer()
|
| 87 |
+
|
| 88 |
+
fun getScore(server: GraphAgentServer): Double =
|
| 89 |
+
when (this) {
|
| 90 |
+
is IsTrue -> {
|
| 91 |
+
server.attributes.filter {
|
| 92 |
+
it.type == type && it is GraphAgentServerAttribute.Boolean && it.value
|
| 93 |
+
}.sumOf { effect.apply() }
|
| 94 |
+
}
|
| 95 |
+
is IsFalse -> {
|
| 96 |
+
server.attributes.filter {
|
| 97 |
+
it.type == type && it is GraphAgentServerAttribute.Boolean && !it.value
|
| 98 |
+
}.sumOf { effect.apply() }
|
| 99 |
+
}
|
| 100 |
+
is IsNotPresent -> {
|
| 101 |
+
val condition = server.attributes.firstOrNull {
|
| 102 |
+
it.type == type
|
| 103 |
+
} == null
|
| 104 |
+
|
| 105 |
+
if (condition) effect.apply() else 0.0
|
| 106 |
+
}
|
| 107 |
+
is IsPresent -> {
|
| 108 |
+
server.attributes.filter {
|
| 109 |
+
it.type == type && it is GraphAgentServerAttribute.Boolean && !it.value
|
| 110 |
+
}.sumOf {
|
| 111 |
+
when (it) {
|
| 112 |
+
is GraphAgentServerAttribute.Number -> effect.apply(it.value)
|
| 113 |
+
else -> effect.apply()
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
is StringEqual -> {
|
| 118 |
+
server.attributes.filter {
|
| 119 |
+
it.type == type && it is GraphAgentServerAttribute.String && it.value == string
|
| 120 |
+
}.sumOf { effect.apply() }
|
| 121 |
+
}
|
| 122 |
+
is StringNotEqual -> {
|
| 123 |
+
server.attributes.filter {
|
| 124 |
+
it.type == type && it is GraphAgentServerAttribute.String && it.value != string
|
| 125 |
+
}.sumOf { effect.apply() }
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
@Serializable
|
| 131 |
+
@JsonClassDiscriminator("type")
|
| 132 |
+
sealed class GraphAgentServerScoring() {
|
| 133 |
+
abstract fun getScore(server: GraphAgentServer): Double
|
| 134 |
+
|
| 135 |
+
@Serializable
|
| 136 |
+
@SerialName("custom")
|
| 137 |
+
@Description("Custom server scoring. Weights can be added on a flat or multiplier basis per attribute")
|
| 138 |
+
data class Custom(
|
| 139 |
+
val scorers: List<GraphAgentServerCustomScorer>
|
| 140 |
+
) : GraphAgentServerScoring() {
|
| 141 |
+
override fun getScore(server: GraphAgentServer): Double {
|
| 142 |
+
return scorers.sumOf { it.getScore(server) }
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
@Serializable
|
| 147 |
+
@SerialName("default")
|
| 148 |
+
@Description("Default server scoring. No weights assigned to any server attribute")
|
| 149 |
+
class Default : GraphAgentServerScoring() {
|
| 150 |
+
override fun getScore(server: GraphAgentServer): Double {
|
| 151 |
+
return 1.0
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
// todo: better defaults/presets
|
| 156 |
+
}
|
src/main/kotlin/org/coralprotocol/coralserver/agent/graph/GraphAgentServerSource.kt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package org.coralprotocol.coralserver.agent.graph
|
| 2 |
+
|
| 3 |
+
import kotlinx.serialization.SerialName
|
| 4 |
+
import kotlinx.serialization.Serializable
|
| 5 |
+
|
| 6 |
+
@Serializable
|
| 7 |
+
sealed class GraphAgentServerSource {
|
| 8 |
+
@Serializable
|
| 9 |
+
@SerialName("servers")
|
| 10 |
+
data class Servers(
|
| 11 |
+
val servers: List<GraphAgentServer>
|
| 12 |
+
) : GraphAgentServerSource()
|
| 13 |
+
|
| 14 |
+
// TODO: implement this properly!
|
| 15 |
+
// an indexer will be a server that will provide another list of servers to query. We will allow people to host
|
| 16 |
+
// their own indexers and we will also provide an indexer connected to our agent marketplace.
|
| 17 |
+
@Serializable
|
| 18 |
+
data class Indexer(
|
| 19 |
+
val indexer: String
|
| 20 |
+
) : GraphAgentServerSource()
|
| 21 |
+
}
|
src/main/kotlin/org/coralprotocol/coralserver/agent/registry/AgentExport.kt
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package org.coralprotocol.coralserver.agent.registry
|
| 2 |
+
|
| 3 |
+
import kotlinx.serialization.SerialName
|
| 4 |
+
import kotlinx.serialization.Serializable
|
| 5 |
+
import org.coralprotocol.coralserver.agent.runtime.RuntimeId
|
| 6 |
+
|
| 7 |
+
@Serializable
|
| 8 |
+
data class AgentExportPricing(
|
| 9 |
+
@SerialName("min_price")
|
| 10 |
+
val minPrice: Double,
|
| 11 |
+
|
| 12 |
+
@SerialName("max_price")
|
| 13 |
+
val maxPrice: Double,
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
@Serializable
|
| 17 |
+
data class AgentExport(
|
| 18 |
+
val agent: RegistryAgent,
|
| 19 |
+
val runtimes: Map<RuntimeId, AgentExportPricing>,
|
| 20 |
+
val quantity: UInt
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
@Serializable
|
| 24 |
+
data class PublicAgentExport(
|
| 25 |
+
val agent: PublicRegistryAgent,
|
| 26 |
+
val runtimes: Map<RuntimeId, AgentExportPricing>,
|
| 27 |
+
val quantity: UInt
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
fun AgentExport.toPublic(id: String): PublicAgentExport {
|
| 31 |
+
return PublicAgentExport(
|
| 32 |
+
agent = agent.toPublic(id),
|
| 33 |
+
runtimes = runtimes,
|
| 34 |
+
quantity = quantity
|
| 35 |
+
)
|
| 36 |
+
}
|
src/main/kotlin/org/coralprotocol/coralserver/agent/registry/AgentOption.kt
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@file:OptIn(ExperimentalSerializationApi::class)
|
| 2 |
+
|
| 3 |
+
package org.coralprotocol.coralserver.agent.registry
|
| 4 |
+
|
| 5 |
+
import kotlinx.serialization.ExperimentalSerializationApi
|
| 6 |
+
import kotlinx.serialization.SerialName
|
| 7 |
+
import kotlinx.serialization.Serializable
|
| 8 |
+
import kotlinx.serialization.json.JsonClassDiscriminator
|
| 9 |
+
|
| 10 |
+
@Serializable
|
| 11 |
+
enum class AgentOptionType {
|
| 12 |
+
@SerialName("string")
|
| 13 |
+
STRING,
|
| 14 |
+
|
| 15 |
+
@SerialName("secret")
|
| 16 |
+
SECRET,
|
| 17 |
+
|
| 18 |
+
@SerialName("number")
|
| 19 |
+
NUMBER,
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
@Serializable
|
| 23 |
+
@JsonClassDiscriminator("type")
|
| 24 |
+
sealed class AgentOption {
|
| 25 |
+
abstract val description: kotlin.String?
|
| 26 |
+
abstract val required: Boolean
|
| 27 |
+
|
| 28 |
+
@Serializable
|
| 29 |
+
@SerialName("string")
|
| 30 |
+
data class String(
|
| 31 |
+
override val description: kotlin.String? = null,
|
| 32 |
+
val default: kotlin.String? = null
|
| 33 |
+
) : AgentOption() {
|
| 34 |
+
override val required: Boolean = default == null
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
@Serializable
|
| 38 |
+
@SerialName("number")
|
| 39 |
+
data class Number(
|
| 40 |
+
override val description: kotlin.String? = null,
|
| 41 |
+
val default: Double? = null,
|
| 42 |
+
) : AgentOption() {
|
| 43 |
+
override val required: Boolean = default == null
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
@Serializable
|
| 47 |
+
@SerialName("secret")
|
| 48 |
+
data class Secret(
|
| 49 |
+
override val description: kotlin.String? = null,
|
| 50 |
+
) : AgentOption() {
|
| 51 |
+
override val required: Boolean = true
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
fun AgentOption.defaultAsValue(): AgentOptionValue? =
|
| 56 |
+
when (this) {
|
| 57 |
+
is AgentOption.String -> this.default?.let { AgentOptionValue.String(it) }
|
| 58 |
+
is AgentOption.Number -> this.default?.let { AgentOptionValue.Number(it) }
|
| 59 |
+
is AgentOption.Secret -> null
|
| 60 |
+
}
|
src/main/kotlin/org/coralprotocol/coralserver/agent/registry/AgentOptionValue.kt
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@file:OptIn(ExperimentalSerializationApi::class)
|
| 2 |
+
|
| 3 |
+
package org.coralprotocol.coralserver.agent.registry
|
| 4 |
+
|
| 5 |
+
import kotlinx.serialization.ExperimentalSerializationApi
|
| 6 |
+
import kotlinx.serialization.SerialName
|
| 7 |
+
import kotlinx.serialization.Serializable
|
| 8 |
+
import kotlinx.serialization.json.JsonClassDiscriminator
|
| 9 |
+
|
| 10 |
+
@Serializable
|
| 11 |
+
@JsonClassDiscriminator("type")
|
| 12 |
+
sealed class AgentOptionValue {
|
| 13 |
+
|
| 14 |
+
@Serializable
|
| 15 |
+
@SerialName("string")
|
| 16 |
+
data class String(val value: kotlin.String) : AgentOptionValue()
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
@Serializable
|
| 20 |
+
@SerialName("number")
|
| 21 |
+
data class Number(val value: Double) : AgentOptionValue()
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
fun AgentOptionValue.toStringValue(): String = when (this) {
|
| 25 |
+
is AgentOptionValue.String -> value
|
| 26 |
+
is AgentOptionValue.Number -> value.toString()
|
| 27 |
+
}
|
src/main/kotlin/org/coralprotocol/coralserver/agent/registry/AgentRegistry.kt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package org.coralprotocol.coralserver.agent.registry
|
| 2 |
+
|
| 3 |
+
import kotlinx.serialization.Serializable
|
| 4 |
+
|
| 5 |
+
@Serializable
|
| 6 |
+
data class AgentRegistry(
|
| 7 |
+
val importedAgents: Map<String, RegistryAgent>,
|
| 8 |
+
val exportedAgents: Map<String, AgentExport>
|
| 9 |
+
)
|