Skip to content

Commit ecdc606

Browse files
initial
0 parents  commit ecdc606

24 files changed

+7015
-0
lines changed

.gitignore

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
.env
8+
.venv/
9+
venv/
10+
ENV/
11+
12+
# Distribution / packaging
13+
dist/
14+
build/
15+
*.egg-info/
16+
17+
# IDE
18+
.idea/
19+
.vscode/
20+
*.swp
21+
*.swo
22+
23+
# Jupyter Notebook
24+
.ipynb_checkpoints
25+
*.ipynb
26+
27+
# UV
28+
.uv/
29+
.python-version
30+
31+
# Logs and databases
32+
*.log
33+
*.sqlite
34+
35+
# Environment variables
36+
.env
37+
.env.*
38+
39+
# OS-specific
40+
.DS_Store
41+
Thumbs.db
42+

README.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Trello Agent
2+
3+
A simple agent that can interact with your Trello boards using natural language. Built with [smolagents](https://github.com/smol-ai/smolagents) - a lightweight framework for building AI agents that can use tools and run code.
4+
5+
## Repository Structure
6+
7+
```
8+
.
9+
├── code/
10+
│ ├── tools.py # Trello API tool implementations
11+
│ └── trello_agent.py # Agent setup and configuration
12+
├── documentation/ # Documentation for smolagents and Trello API
13+
├── .env.example # Template for environment variables
14+
└── README.md
15+
```
16+
17+
## Setup
18+
19+
1. Install `uv` (Python package manager):
20+
```bash
21+
curl -LsSf https://astral.sh/uv/install.sh | sh
22+
```
23+
24+
2. Copy the environment variables file and fill in your credentials:
25+
```bash
26+
cp .env.example .env
27+
```
28+
29+
Required environment variables:
30+
- `TRELLO_API_KEY` & `TRELLO_TOKEN`: Create at [Trello Power-Ups Admin](https://trello.com/power-ups/admin)
31+
- `TRELLO_BOARD_ID`: ID of your default Trello board
32+
- `HUGGINGFACE_TOKEN`: Create at [HuggingFace Settings](https://huggingface.co/settings/tokens)
33+
34+
3. Install dependencies and run:
35+
```bash
36+
uv run code/trello_agent.py
37+
```
38+
This command will create a virtual environment and run the agent with an example prompt.
39+
40+
Alternatively, you can install dependencies separately:
41+
```bash
42+
uv sync
43+
source .venv/bin/activate
44+
python code/trello_agent.py
45+
```
46+
47+
The agent can help you with tasks like:
48+
- Listing your Trello boards, lists, and cards
49+
- Creating new tickets
50+
- Finding tasks to work on
51+
52+
You can use the `code/test_trello_client.ipynb` Jupyter notebook to test the Trello API directly:
53+
54+
## How it Works
55+
56+
This project uses:
57+
- `smolagents`: A lightweight framework for building AI agents
58+
- `py-trello`: Python wrapper for the Trello API
59+
60+
The agent is structured into two main components:
61+
1. `tools.py`: Contains all the Trello API interactions (creating cards, listing boards, etc.)
62+
2. `trello_agent.py`: Sets up the AI agent with the tools and handles natural language processing
63+
64+
65+
## Documentation
66+
67+
Check the `documentation/` folder for detailed information about:
68+
- smolagents library usage and features
69+
- Trello API documentation and examples

code/code_agent.py

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# !uv add smolagents py-trello python-dotenv arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp openinference-instrumentation-smolagents
2+
3+
from opentelemetry import trace
4+
from opentelemetry.sdk.trace import TracerProvider
5+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
6+
from opentelemetry.trace import Status, StatusCode
7+
8+
from openinference.instrumentation.smolagents import SmolagentsInstrumentor
9+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
10+
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
11+
12+
from smolagents import CodeAgent, ToolCallingAgent, HfApiModel, ManagedAgent, tool
13+
from trello import TrelloClient
14+
import os
15+
from dotenv import load_dotenv
16+
from typing import List, Optional, Dict, Any
17+
from datetime import datetime
18+
import json
19+
import requests
20+
21+
# Load environment variables
22+
load_dotenv()
23+
24+
# Setup OpenTelemetry with a single tracer
25+
endpoint = "http://0.0.0.0:6006/v1/traces"
26+
trace.set_tracer_provider(TracerProvider())
27+
tracer = trace.get_tracer(__name__)
28+
otlp_exporter = OTLPSpanExporter(endpoint=endpoint)
29+
trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(otlp_exporter))
30+
31+
# Initialize Trello client
32+
client = TrelloClient(
33+
api_key=os.getenv('TRELLO_API_KEY'),
34+
token=os.getenv('TRELLO_TOKEN')
35+
)
36+
board = client.get_board(os.getenv('TRELLO_BOARD_ID'))
37+
38+
# Create documentation search tool
39+
@tool
40+
def search_documentation(query: str) -> str:
41+
"""Search the py-trello documentation for specific information.
42+
43+
Args:
44+
query: The search query about Trello client functionality
45+
46+
Returns:
47+
str: Relevant documentation information
48+
"""
49+
# This is a simplified version - in reality you might want to use a more sophisticated
50+
# documentation search system or maintain local documentation
51+
base_url = "https://raw.githubusercontent.com/sarumont/py-trello/master/docs/"
52+
docs = [
53+
"api-members.rst",
54+
"api-boards.rst",
55+
"api-cards.rst",
56+
"api-lists.rst",
57+
"api-organizations.rst"
58+
]
59+
60+
results = []
61+
for doc in docs:
62+
try:
63+
response = requests.get(f"{base_url}{doc}")
64+
if response.status_code == 200:
65+
content = response.text
66+
if query.lower() in content.lower():
67+
relevant_lines = [line.strip() for line in content.split('\n')
68+
if query.lower() in line.lower()]
69+
if relevant_lines:
70+
results.append(f"From {doc}:")
71+
results.extend(relevant_lines)
72+
except Exception as e:
73+
continue
74+
75+
return "\n".join(results) if results else "No relevant documentation found."
76+
77+
# Create the documentation search agent
78+
doc_search_agent = ToolCallingAgent(
79+
tools=[search_documentation],
80+
model=HfApiModel(),
81+
system_message="""You are a documentation search assistant for the py-trello library.
82+
Your role is to search and interpret the documentation to help understand how to use the Trello client.
83+
When asked a question, search the documentation and provide relevant information about the Trello client's capabilities."""
84+
)
85+
86+
# Wrap the doc search agent as a managed agent
87+
managed_doc_agent = ManagedAgent(
88+
agent=doc_search_agent,
89+
name="doc_search",
90+
description="Searches and interprets py-trello documentation. Use this when you need to understand how to use specific Trello client features."
91+
)
92+
93+
# Create the main code agent with access to the Trello client and managed doc agent
94+
code_agent = CodeAgent(
95+
tools=[], # No direct tools needed
96+
model=HfApiModel(),
97+
managed_agents=[managed_doc_agent],
98+
system_message="""You are a Trello automation assistant that can directly interact with the Trello API using the py-trello library.
99+
You have access to the following objects:
100+
- client: A TrelloClient instance already configured with API credentials
101+
- board: The current Trello board object
102+
103+
When you need to understand how to use specific Trello client features, you can ask the doc_search agent for help.
104+
Example: result = doc_search("how to create a card")
105+
106+
Key capabilities of the Trello client:
107+
1. List operations:
108+
- board.list_lists() -> Get all lists
109+
- list.list_cards() -> Get all cards in a list
110+
111+
2. Card operations:
112+
- list.add_card(name, desc) -> Create new card
113+
- card.set_name(name) -> Update card title
114+
- card.set_description(desc) -> Update description
115+
- card.change_list(list_id) -> Move card to different list
116+
- card.add_label(label) -> Add label to card
117+
118+
3. Label operations:
119+
- board.get_labels() -> Get all available labels
120+
121+
You can write and execute Python code to perform any Trello operations using these objects.
122+
If you're unsure about how to use a specific feature, ask the doc_search agent for help.
123+
Always handle errors appropriately and provide clear feedback about operations performed."""
124+
)
125+
126+
if __name__ == "__main__":
127+
task = 'list the names of all boards the user has access to'
128+
129+
# Run the task with tracing
130+
with tracer.start_as_current_span("trello_task") as span:
131+
try:
132+
result = code_agent.run(task)
133+
span.set_status(Status(StatusCode.OK))
134+
except Exception as e:
135+
span.set_status(Status(StatusCode.ERROR), str(e))
136+
raise

0 commit comments

Comments
 (0)