Skip to content

Commit

Permalink
adding guide for AVCTL hosting
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Croft authored and Joshua Croft committed Nov 6, 2024
1 parent dc42bcf commit 9936b7b
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 0 deletions.
211 changes: 211 additions & 0 deletions pages/guides/agentverse/avctl/avctl-ci-github.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
import { Callout } from 'nextra/components'
import agentverse_secret from 'src/images/guides/agentverse/avctl/agentverse_secret.png';
import github_secret from 'src/images/guides/agentverse/avctl/github_secret.png';
import action from 'src/images/guides/agentverse/avctl/action.png';
import { ImageByTheme } from "components/mdx"
import {CodeSegment, GithubCodeSegment} from "../../../../components/code";

# CI with AVCTL and github actions

This guide explains how we deploy an agent, or update a deployed agent on agentverse using AVCTL.

## Structure

We have a [github repo](https://github.com/fetchai/avctl-ci-example) where you can clone this code.

It is made up of three parts, but really two we have our deployment scripts in .github/workflows and in scripts/ and our agen is under agent/.

```
├── README.md
├── .github
│ └── workflows
│ └── deploy-agent.yaml
├── agent
│ ├── README.md
│ ├── agent.py
│ ├── poetry.lock
| └── pyproject.toml
└── scripts
└── deploy-agent.sh
```

This logic is very simple, we have a github workflow that triggers when the branch main is updated. It then call the
deployment script in `scripts/deploy-agent.sh`, this script works as follows:

Check if the agent already has an address defined in `.avctl/config.toml`, if it does is this agent registered? If
it isn't, let's register this agent. If it is registered let's stop this agent and sync it.

You can see the deplot script below, or on [github](https://github.com/fetchai/avctl-ci-example/blob/main/scripts/deploy-agent.sh)

<GithubCodeSegment digest="d6ffbd71cd64db449cca201ec19d7eff">
<CodeSegment
path="https://github.com/fetchai/avctl-ci-example/blob/main/scripts/deploy-agent.sh"
lineStart={1}
lineEnd={52}
hosted={true}
/>
</GithubCodeSegment>
<CodeGroup dynamic hasCopy isLocalHostedFile digest='d6ffbd71cd64db449cca201ec19d7eff'>

<DocsCode local={true}>
```py copy filename="deploy-agent.sh"

# Define the function
get_agent_address() {
local file=".avctl/config.toml "

# Check if the file exists
if [ -f "$file" ]; then
# Extract the address value
agent_address=$(grep 'address =' "$file" | sed -E 's/.*= "(.*)"/\1/')

# Check if the address is not empty
if [ -n "$agent_address" ]; then
echo $agent_address
else
echo ""
fi
else
echo ""
fi
}

# Define the specific directory to work on
defined_directory="agent/"

# Change to the specified agent directory
cd "$defined_directory"

# Create a .staging.avctl folder for new agents if it doesn't exist
avctl hosting init

# get the agent address if it exists
agent_address=$(get_agent_address)

# Get the agent's name from the README.md top line header
agent_name=$(head -n 1 README.md | sed -e 's/#//g' | xargs)


# If the address exists...
if [ -n "$agent_address" ]; then
avctl hosting get agent -a "$agent_address"
response=$(avctl hosting get agent -a "$agent_address")\

# Check if the agent is already in existence, if it isn't, deploy as new, else sync.
if [ $? -eq 0 ]; then
avctl hosting stop -a "$agent_address"
avctl hosting sync -a "$agent_address"
else
avctl hosting deploy -n "$agent_name" --no-dependency-check || true
fi
# Agent doesn't exist, so let's deploy
else
avctl hosting deploy -n "$agent_name" --no-dependency-check || true
fi

```
</DocsCode>

</CodeGroup>



## Getting started

Head on over to [agentverse.ai](https://agentverse.ai) and sign in, under your profile link (top right) there is an
option for `API Keys`:

<ImageByTheme
darkSrc={agentverse_secret}
lightSrc={agentverse_secret}
alt="agentverse_secret"
/>

Click this take syou to an API Key window, here click new `+ New API Key`, give the key a name and give this api key
full permissions. Click generate API Key at the bottom of the page, and copy the output. Detailed instructions can
also be found [here](/guides/apis/agent-function-creation-apis#how-to-get-agentverse-api-tokens)

Once you've got your API_KEY, be sure to have forked the [github repo](https://github.com/fetchai/avctl-ci-example),
and visit that repo. Go to settings, on the left hand menu select Secrets and variables, and click actions from the
drop down. You'll get a window like shown below:

<ImageByTheme
darkSrc={github_secret}
lightSrc={github_secret}
alt="github_secret"
/>

Click New Repository secret and enter the API_KEY, we have named ours `AGENTVERSE_API_KEY`.

Great with that set, copy in your agent code under agent. It is assumed here that your agent is tested, and you have
an account on agentverse.

Now, let's push:

```
git add .
git commit -m "updating agent"
git push
```
Vistit your forked repo github page, and under actions you should see the runner in action:

<ImageByTheme
darkSrc={action}
lightSrc={action}
alt="action of github runner"
/>

### Possible error

You may need to locally run:

```
sudo git update-index --chmod=+x scripts/deploy-agent.sh
```

This tells git to update the permission on the executable script. Then push up the changes for them to take effect.

## Running this locally:

Please follow the installation guide [here](guides/agentverse/avctl/avctl#installation)

Update the permissions on deploy-agent.sh (You should only need to do this once):

```
chmod +x scripts/deploy-agent.sh
```

Login to agentverse from terminal:

```
avctl auth login
```

Then from terminal run:

```
./scripts/deploy-agent.sh
```

You should see output similar too, dependent on your agents deployed state:

```
josh@vm avctl-ci-example % ./scripts/deploy-agent.sh
Project already initialized
Agent exists on agentverse under address: 'agent1qfx5mmewjs4x9ysyxemsaxv6empds4mmpx4sav84yagmhed5yczdwtqkcxu'
Agent agent1qfx5mmewjs4x9ysyxemsaxv6empds4mmpx4sav84yagmhed5yczdwtqkcxu has been stopped.
Pushing latest code...
Everything is up to date. Nothing to push
Agent agent1qfx5mmewjs4x9ysyxemsaxv6empds4mmpx4sav84yagmhed5yczdwtqkcxu is now running!
josh@vm avctl-ci-example %
```

## Quirks

Agentvese for security defines your agent address and stores your private key. An address you set locally will not be applied on agentverse using the above method.

## Further steps

To get familiar with AVCTl we recommend reading the other guides in this series: [avctl](guides/agentverse/avctl/avctl), [avct hosting](guides/agentverse/avctl/avctl-hosting).

Binary file added src/images/guides/agentverse/avctl/action.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9936b7b

Please sign in to comment.