Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.
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
37 changes: 37 additions & 0 deletions .github/workflows/docker-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build Docker Images

on:
release:
types: [published]

permissions:
contents: read

jobs:
build-api-image:
runs-on: ubuntu-latest

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

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker Login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ vars.DOCKERHUB_NAMESPACE }}/agent-api:dev, ${{ vars.DOCKERHUB_NAMESPACE }}/agent-api:prd
44 changes: 44 additions & 0 deletions .github/workflows/ecr-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build ECR Images

on: workflow_dispatch

permissions:
# For AWS OIDC Token access as per https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services#updating-your-github-actions-workflow
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

env:
ECR_REPO: YOUR ECR REPO
# Create role using https://aws.amazon.com/blogs/security/use-iam-roles-to-connect-github-actions-to-actions-in-aws/
AWS_ROLE: YOUR_ROLE_ARN
AWS_REGION: us-east-1

jobs:
build-api-image:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# https://github.com/marketplace/actions/configure-aws-credentials-action-for-github-actions
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.AWS_ROLE }}
aws-region: ${{ env.AWS_REGION }}
# https://github.com/marketplace/actions/amazon-ecr-login-action-for-github-actions
- name: ECR Login
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build, tag, and push docker image to Amazon ECR
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.ECR_REPO }}/agent-api:dev, ${{ env.ECR_REPO }}/agent-api:prd
49 changes: 49 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Validate

on:
push:
branches:
- "main"
pull_request:
types:
- opened
- synchronize
- reopened
branches:
- "main"

jobs:
validate:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: "requirements**.txt"

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install the project
run: uv pip sync requirements.txt

- name: Format with ruff
run: uv run ruff format .

- name: Lint with ruff
run: uv run ruff check .

- name: Type-check with mypy
run: uv run mypy .

# - name: Run tests
# run: uv run pytest tests
65 changes: 35 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,69 @@
## Api Workspace Template
## Sample Agentic Application

This repo contains the code for running an agent-app and supports 2 environments:
This repo contains the code for a running an agentic application with:

1. **dev**: A development environment running locally on docker
2. **prd**: A production environment running on AWS ECS
1. A FastAPI server
2. A Postgres database with the PgVector extension.

## Setup Workspace
You can run the agentic application in 2 environments:

1. [Install uv](https://docs.astral.sh/uv/#getting-started): `curl -LsSf https://astral.sh/uv/install.sh | sh`

> from the `agent-api-template` dir:
1. A development environment running locally on docker
2. A production environment running on AWS ECS

2. Install workspace and activate the virtual env:
## Setup

```sh
./scripts/install.sh
source .venv/bin/activate
```
1. [Install uv](https://docs.astral.sh/uv/#getting-started): `curl -LsSf https://astral.sh/uv/install.sh | sh`

3. Copy `workspace/example_secrets` to `workspace/secrets`:
2. Create a virtual environment and install dependencies:

```sh
cp -r workspace/example_secrets workspace/secrets
./scripts/dev_setup.sh
```

4. Optional: Create `.env` file:
3. Activate virtual environment

```sh
cp example.env .env
```
source .venv/bin/activate
```

## Run Api Workspace Template locally
## Run application locally using docker

1. Install [docker desktop](https://www.docker.com/products/docker-desktop)

2. Set OpenAI Key
2. Export API keys

Set the `OPENAI_API_KEY` environment variable using
Required: Set the `OPENAI_API_KEY` environment variable using

```sh
export OPENAI_API_KEY=sk-***
export OPENAI_API_KEY=***
```

**OR** set in the `.env` file
> you may use any model provider, just need to update the /agents

Optional: Set the `EXA_API_KEY` if you'd like to use Exa search

```sh
export EXA_API_KEY=***
```

3. Start the workspace using:
3. Start the workspace:

```sh
ag ws up dev
ag ws up
```

Open [localhost:8000/docs](http://localhost:8000/docs) to view the FastAPI docs.
Open [localhost:8501](http://localhost:8501) to view the Streamlit App.
- This will run 3 containers:
- FastAPI on [localhost:8000](http://localhost:8000/docs)
- Postgres on [localhost:5432](http://localhost:5432)
- Open [localhost:8501](http://localhost:8501) to view the Streamlit App.
- Open [localhost:8000/docs](http://localhost:8000/docs) to view the FastAPI docs.

4. Stop the workspace using:

```sh
ag ws down dev
ag ws down
```

## Next Steps:
## Learn more:

- Run the Api Workspace Template on AWS - Docs coming soon
- Learn more about this template and how to customize it.
17 changes: 14 additions & 3 deletions agents/agents.py → agents/operator.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
from typing import Optional
from enum import Enum
from typing import List, Optional

from agents.sage import get_sage
from agents.scholar import get_scholar


class AgentType(Enum):
SAGE = "sage"
SCHOLAR = "scholar"


def get_available_agents() -> List[str]:
"""Returns a list of all available agent IDs."""
return [agent.value for agent in AgentType]


def get_agent(
model_id: str = "gpt-4o",
agent_id: Optional[str] = None,
agent_id: Optional[AgentType] = None,
user_id: Optional[str] = None,
session_id: Optional[str] = None,
debug_mode: bool = True,
):
if agent_id == "sage":
if agent_id == AgentType.SAGE:
return get_sage(model_id=model_id, user_id=user_id, session_id=session_id, debug_mode=debug_mode)
else:
return get_scholar(model_id=model_id, user_id=user_id, session_id=session_id, debug_mode=debug_mode)
Loading
Loading