-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from alipay/dev
feat: Release version 0.0.6
- Loading branch information
Showing
11 changed files
with
490 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
## gRPC | ||
In addition to HTTP API, we also provide a built-in GRPC Agent service server. | ||
|
||
### Starting gRPC server | ||
If you need to enable GRPC server, you can configure it in the config.toml file as follows: | ||
```toml | ||
[GRPC] | ||
activate = 'true' | ||
max_workers = 10 | ||
server_port = 50051 | ||
``` | ||
- **activate**: The gRPC server starts only when this value is set to `true`. | ||
- **max_workers**: The maximum number of threads in the gRPC server thread pool, with a default of 10. | ||
- **server_port**: The service port of the gRPC server, with a default of 50051. | ||
|
||
### Calling the gRPC Service | ||
|
||
### Interface Definition | ||
The complete definition file for the gRPC service interface is as follows: | ||
```text | ||
syntax = "proto3"; | ||
package agentuniverse; | ||
service AgentUniverseService { | ||
rpc service_run(AgentServiceRequest) returns (AgentServiceResponse); | ||
rpc service_run_async(AgentServiceRequest) returns (AgentServiceResponse); | ||
rpc service_run_result(AgentResultRequest) returns (AgentServiceResponse); | ||
} | ||
message AgentServiceRequest { | ||
string service_id = 1; | ||
string params = 2; | ||
bool saved = 3; | ||
} | ||
message AgentServiceResponse { | ||
string message = 1; | ||
bool success = 2; | ||
string request_id = 3; | ||
string result = 4; | ||
} | ||
message AgentResultRequest { | ||
string request_id = 1; | ||
} | ||
``` | ||
\ | ||
Similar to the [Web API](2_4_1_Web_Api.md), the gRPC service includes three interfaces: | ||
```text | ||
service AgentUniverseService { | ||
rpc service_run(AgentServiceRequest) returns (AgentServiceResponse); | ||
rpc service_run_async(AgentServiceRequest) returns (AgentServiceResponse); | ||
rpc service_run_result(AgentResultRequest) returns (AgentServiceResponse); | ||
} | ||
``` | ||
- **service_run**: Synchronously calls an Agent service, blocking during the call until the Agent returns results. | ||
- **service_run_async**: Asynchronously calls an Agent service, initially returning a `request_id`, and the result of the Agent service can be queried later using the `service_run_result` interface with this ID. | ||
- **service_run_result**: Queries the result of the Agent service.。 | ||
|
||
\ | ||
The request body structure for calling an Agent service is as follows:: | ||
```text | ||
message AgentServiceRequest { | ||
string service_id = 1; | ||
string params = 2; | ||
bool saved = 3; | ||
} | ||
``` | ||
- **service_id**: The model service id registered in the application.。 | ||
- **params**: The service input parameters in JSON String format, which will be parsed by `json.loads` into the form of `**kwargs` passed to the underlying Agent. | ||
- **saved**: Whether to save the result of this request. If the value is `false`, the result of this request cannot be queried in `service_run_result`. | ||
|
||
\ | ||
The request body structure for querying the result of an Agent service is as follows: | ||
```text | ||
message AgentResultRequest { | ||
string request_id = 1; | ||
} | ||
``` | ||
- **request_id**: The request ID to be queried. | ||
|
||
\ | ||
The structure of the return result is as follows: | ||
```text | ||
message AgentServiceResponse { | ||
string message = 1; | ||
bool success = 2; | ||
string request_id = 3; | ||
string result = 4; | ||
} | ||
``` | ||
- **message**: Detailed error information when the request fails. | ||
- **success**: Indicates whether the request was successfully executed. | ||
- **request_id**: The ID of this request. | ||
- **result**: The result of executing the Agent service. It is empty in the asynchronous interface `service_run_async`. | ||
|
||
### Call Example | ||
```python | ||
import grpc | ||
from agentuniverse.agent_serve.web.rpc.grpc import agentuniverse_service_pb2, \ | ||
agentuniverse_service_pb2_grpc | ||
|
||
|
||
# Start you server_application first. | ||
def test_run(): | ||
with grpc.insecure_channel('localhost:50051') as channel: | ||
stub = agentuniverse_service_pb2_grpc.AgentUniverseServiceStub(channel) | ||
response = stub.service_run(agentuniverse_service_pb2.AgentServiceRequest( | ||
service_id='demo_service', | ||
params='{"input":"(18+3-5)/2*4=?"}', | ||
saved=True | ||
)) | ||
print("client received: " + response.request_id) | ||
|
||
response = stub.service_run_result(agentuniverse_service_pb2.AgentResultRequest( | ||
request_id=response.request_id | ||
)) | ||
print("client received: " + response.result) | ||
``` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# High Availability Deployment with K8S | ||
AgentUniverse provides standard working environment images, designed to support containerized deployments on Kubernetes (K8S) clusters. This guide will show you how to utilize these working environment images to deploy and set up a cluster on K8S. | ||
Official K8S Documentation: [Kubernetes Setup Documentation](https://kubernetes.io/docs/setup/) | ||
|
||
## 1. Resource Configuration | ||
First, you need to configure the necessary resource files. Below is an example used to define the required Namespace, Deployment, and Service resources using a YAML configuration file: | ||
|
||
```yaml | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: agent-namespace | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: agentuniverse-deployment | ||
namespace: agent-namespace | ||
labels: | ||
app: agentuniverse | ||
spec: | ||
replicas: 3 | ||
selector: | ||
matchLabels: | ||
app: agentuniverse | ||
template: | ||
metadata: | ||
labels: | ||
app: agentuniverse | ||
spec: | ||
containers: | ||
- name: agentuniverse-container | ||
image: registry.cn-hangzhou.aliyuncs.com/agent_universe/agent_universe:0.0.5_centos8_beta | ||
ports: | ||
- containerPort: 8888 | ||
command: ["/bin/bash", "-c"] | ||
args: ["git clone [email protected]:alipay/agentUniverse.git; mv agentUniverse/sample_standard_app /usr/local/etc/workspace/project; /bin/bash --login /usr/local/etc/workspace/shell/start.sh"] | ||
# Uncomment and replace "XXX" with your key to configure the agent | ||
# env: | ||
# - name: OPENAI_API_KEY | ||
# value: "XXX" | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: agentuniverse-service | ||
namespace: agent-namespace | ||
spec: | ||
selector: | ||
app: agentuniverse | ||
ports: | ||
- protocol: TCP | ||
port: 9999 | ||
targetPort: 8888 | ||
``` | ||
### 1.1 Setting Environment Variables for AgentUniverse Project | ||
#### Method 1 (Recommended) | ||
In the resource configuration file, uncomment the `env` section and replace `value` with your key. For additional security considerations, it's recommended to use K8S officially recommended methods, such as ConfigMap. See the [ConfigMap Configuration Documentation](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/). | ||
|
||
#### Method 2 | ||
|
||
Please refer to the description at the beginning of the configuration file: [Quick Start Guide](https://github.com/alipay/agentUniverse/blob/master/docs/guidebook/zh/1_3_快速开始.md) | ||
|
||
## 2. Building Resources | ||
|
||
Create and apply the aforementioned configuration file: | ||
|
||
``` | ||
kubectl apply -f agentuniverse.yaml | ||
``` | ||
|
||
## 3. Verifying Resources | ||
|
||
Verify that all resources have been correctly deployed: | ||
|
||
``` | ||
kubectl get all -n agent-namespace | ||
``` | ||
|
||
![Resource Deployment Status](../_picture/k8s_resource.png) | ||
|
||
## 4. Accessing AgentUniverse Services from Inside the Cluster | ||
|
||
To access AgentUniverse services from within the cluster, use the following command line example: | ||
|
||
``` | ||
kubectl exec -it [Pod Name] -n agent-namespace -- curl http://agentuniverse-service:9999 | ||
``` | ||
|
||
### 4.1 Examples | ||
|
||
#### 4.1.1 Connectivity Test | ||
|
||
``` | ||
kubectl exec -it agentuniverse-deployment-55cfd778d-g7d9d -n agent-namespace -- curl http://agentuniverse-service:9999/echo | ||
``` | ||
![Connectivity Test](../_picture/k8s_hello.png) | ||
#### 4.1.2 Q&A Test | ||
``` | ||
kubectl exec -it agentuniverse-deployment-55cfd778d-g7d9d -n agent-namespace -- curl -X POST -H "Content-Type: application/json" -d '{"service_id":"demo_service","params":{"input":"(18+3-5)/2*4=?"}}' http://agentuniverse-service:9999/service_run | ||
``` | ||
![Q&A Test](../_picture/k8s_question.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.