Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker image build and FlyteAgent update steps to "Developing agents" doc #5009

Merged
merged 4 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 80 additions & 2 deletions docs/flyte_agents/developing_agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ While agents can be written in any programming language, we currently only suppo

```

## Async agent interface specification
## Steps

### 1. Implement required methods

#### Async agent interface specification

To create a new async agent, extend the [`AsyncAgentBase`](https://github.com/flyteorg/flytekit/blob/master/flytekit/extend/backend/base_agent.py#L127) class and implement `create`, `get`, and `delete` methods. These methods must be idempotent.

Expand Down Expand Up @@ -76,7 +80,7 @@ AgentRegistry.register(BigQueryAgent())

For an example implementation, see the [BigQuery agent](https://github.com/flyteorg/flytekit/blob/master/plugins/flytekit-bigquery/flytekitplugins/bigquery/agent.py#L43).

## Sync agent interface specification
#### Sync agent interface specification

To create a new sync agent, extend the [`SyncAgentBase`](https://github.com/flyteorg/flytekit/blob/master/flytekit/extend/backend/base_agent.py#L107) class and implement a `do` method. This method must be idempotent.

Expand All @@ -98,3 +102,77 @@ class OpenAIAgent(SyncAgentBase):

AgentRegistry.register(OpenAIAgent())
```

### 2. Test the agent locally

See {doc}`"Testing agents locally" <testing_agents_locally>` to test your agent locally.

### 3. Build a new Docker image

The following is a sample Dockerfile for building an image for a Flyte agent:

```Dockerfile
FROM python:3.9-slim-buster

MAINTAINER Flyte Team <[email protected]>
LABEL org.opencontainers.image.source=https://github.com/flyteorg/flytekit

WORKDIR /root
ENV PYTHONPATH /root

# flytekit will autoload the agent if package is installed.
RUN pip install flytekitplugins-bigquery
CMD pyflyte serve agent --port 8000
```

:::{note}
For flytekit versions `<=v1.10.2`, use `pyflyte serve`.
For flytekit versions `>v1.10.2`, use `pyflyte serve agent`.
:::

### 4. Update FlyteAgent

1. Update the FlyteAgent deployment's [image](https://github.com/flyteorg/flyte/blob/master/charts/flyteagent/templates/agent/deployment.yaml#L35)
2. Update the FlytePropeller configmap.

```YAML
tasks:
task-plugins:
enabled-plugins:
- agent-service
default-for-task-types:
- bigquery_query_job_task: agent-service
- custom_task: agent-service

plugins:
agent-service:
supportedTaskTypes:
- bigquery_query_job_task
- default_task
- custom_task
# By default, all requests will be sent to the default agent.
defaultAgent:
endpoint: "dns:///flyteagent.flyte.svc.cluster.local:8000"
insecure: true
timeouts:
GetTask: 5s
defaultTimeout: 10s
agents:
custom_agent:
endpoint: "dns:///custom-flyteagent.flyte.svc.cluster.local:8000"
insecure: false
defaultServiceConfig: '{"loadBalancingConfig": [{"round_robin":{}}]}'
timeouts:
GetTask: 5s
defaultTimeout: 10s
agentForTaskTypes:
# It will override the default agent for custom_task, which means propeller will send the request to this agent.
- custom_task: custom_agent
```

3. Restart the FlytePropeller

```
kubectl rollout restart deployment flytepropeller -n flyte
```

234 changes: 0 additions & 234 deletions docs/user_guide/development_lifecycle/agents.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/user_guide/development_lifecycle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ You will gain an understanding of concepts like caching, the Flyte remote API, A
:name: development_lifecycle_toc
:hidden:

agents
private_images
caching
cache_serializing
Expand Down
2 changes: 1 addition & 1 deletion docs/user_guide/extending/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ of the plugin.

_New in Flyte 1.7.0_

{ref}`Flyte Agent Service <extend-agent-service>` allows you to write backend
The {ref}`Flyte Agent service <flyte_agents_guide>` allows you to write backend
plugins in Python.

### Summary
Expand Down
Loading