Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
devjsc authored and Joshua Croft committed Nov 6, 2024
0 parents commit 93d4206
Show file tree
Hide file tree
Showing 9 changed files with 1,691 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/deploy-agent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Deploy Agents to Production

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download latest AVCTL release binary
run: |
LATEST_RELEASE_URL=$(curl -s https://api.github.com/repos/fetchai/avctl/releases/latest \
| grep browser_download_url \
| grep avctl_Linux_x86_64.tar.gz \
| cut -d '"' -f 4)
curl -L -o avctl_Linux_x86_64.tar.gz $LATEST_RELEASE_URL

- name: Extract binary and install
run: |
tar -xvf avctl_Linux_x86_64.tar.gz
chmod +x avctl
mv avctl /usr/local/bin/avctl
- name: Authenticate with Agentverse
run: avctl auth token ${{ secrets.AGENTVERSE_API_KEY }}

- name: Deploy all agents
run: ./scripts/deploy-agent.sh
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
.idea
.env
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# avctl-github-ci-example

AVCTL gives you the luxury of being able to deploy your agents to the [cloud]() with simple command line instructions. We've tried created this repository as a template for you to integrate AVCTL and Github Actions to have a simple workflow of development and deployment.

This repo contains two parts, deployment scripts and the agent itself.

### Development

It is recommended you fork this repo to build from, and this page instructions assumes you have.

In our agent folder, we have a very simple Alice agent. We've initalised a poetry file too. Poetry is used to build the agent in the deployment section, we see it as beneficial too for containing our package versions. If you're unfamiliar with poetry and agent installation, check out the [docs](https://fetch.ai/docs).

For more advanced agent examples, check out templates on [agentverse.ai](https://agentverse.ai)

### Deployment

You will need to go to agentverse.ai and create an API key and create this as an action secret in github.

Our action is set to run on pushes to main, this works for simplicity but it is recommended you update the workflow to only run on merges into a branch like `release/production`, one which has appropriate branch protection rules.

If you make a change to your agent and push, you'll see the workflow run.


### Agent private keys & addresses

Agents identified by addresses derived from private keys. When building and deploying agents on agentverse, agentverse will create your private key and address for you. To learn more about agent addresses and seeds, please visit the [fetch.ai/docs](https://fetch.ai/docs)
3 changes: 3 additions & 0 deletions agent/.avctl/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[agent]
address = "agent1qfx5mmewjs4x9ysyxemsaxv6empds4mmpx4sav84yagmhed5yczdwtqkcxu"
include = ""
1 change: 1 addition & 0 deletions agent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# ALICE from terminator
21 changes: 21 additions & 0 deletions agent/agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Import necessary classes from the uAgents library
from uagents import Agent, Context

# Create an agent named alice
agent = Agent(
name="alice from the future",
port=8001,
seed="eubrpq3ibrfpiebrpivqepirvpierbvpiberpb"
)


# Function to be called when the agent is started
@agent.on_event("startup")
async def introduce_agent(ctx: Context):
# Print a greeting message with the agent's name and its address
print(f"Hello, I'm agent {agent.name} and my address is {agent.address}.")


# Run the agent only when the script is executed directly
if __name__ == "__main__":
agent.run()
1,535 changes: 1,535 additions & 0 deletions agent/poetry.lock

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions agent/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[tool.poetry]
name = "agent"
version = "0.1.0"
description = ""
authors = ["None"]
readme = "README.md"

[tool.poetry.dependencies]
python = "3.11"
uagents = "^0.17.1"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
52 changes: 52 additions & 0 deletions scripts/deploy-agent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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

0 comments on commit 93d4206

Please sign in to comment.