-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrewai-tools.py
More file actions
134 lines (107 loc) · 4.67 KB
/
crewai-tools.py
File metadata and controls
134 lines (107 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
"""
CrewAI Tools with Frostbyte APIs
=================================
Build CrewAI agents with real-world capabilities: IP geolocation,
crypto market data, DNS analysis, web scraping, and code execution.
Requirements:
pip install crewai requests
Usage:
export FROSTBYTE_API_KEY="your-key" # Get free: https://ozorown.github.io
export OPENAI_API_KEY="sk-..."
python crewai-tools.py
"""
import json
import os
import requests
from crewai import Agent, Task, Crew
from crewai.tools import tool
FROSTBYTE_BASE = "https://api-catalog-three.vercel.app/v1"
API_KEY = os.environ.get("FROSTBYTE_API_KEY", "")
HEADERS = {"Authorization": f"Bearer {API_KEY}"}
# --- CrewAI Tool Definitions ---
@tool("IP Geolocation Lookup")
def geo_lookup(ip: str) -> str:
"""Look up geolocation data for an IP address. Returns country, city, ISP, lat/lon coordinates."""
r = requests.get(f"{FROSTBYTE_BASE}/agent-geo/geo/{ip}", headers=HEADERS)
return json.dumps(r.json(), indent=2)
@tool("Cryptocurrency Price Check")
def crypto_price(symbol: str) -> str:
"""Get current price, 24h change, and market cap for a cryptocurrency. Use names like 'bitcoin', 'ethereum', 'solana'."""
r = requests.get(f"{FROSTBYTE_BASE}/crypto-feeds/prices/{symbol}", headers=HEADERS)
return json.dumps(r.json(), indent=2)
@tool("DNS Record Lookup")
def dns_lookup(domain: str) -> str:
"""Resolve DNS records for a domain. Returns A, AAAA, MX, NS, and TXT records."""
r = requests.get(f"{FROSTBYTE_BASE}/agent-dns/api/resolve/{domain}", headers=HEADERS)
return json.dumps(r.json(), indent=2)
@tool("Web Scraper")
def scrape_url(url: str) -> str:
"""Scrape a webpage and extract its text content, title, and metadata."""
r = requests.post(f"{FROSTBYTE_BASE}/agent-scraper/api/scrape",
headers={**HEADERS, "Content-Type": "application/json"},
json={"url": url})
data = r.json()
return json.dumps({
"title": data.get("title", ""),
"text": data.get("text", "")[:2000],
}, indent=2)
@tool("Code Executor")
def run_code(language: str, code: str) -> str:
"""Execute code in a sandbox. Supports: python3, javascript, bash, ruby, go, rust."""
r = requests.post(f"{FROSTBYTE_BASE}/agent-coderunner/api/execute",
headers={**HEADERS, "Content-Type": "application/json"},
json={"language": language, "code": code})
return json.dumps(r.json(), indent=2)
# --- CrewAI Agent & Task Setup ---
def run_crew():
"""Run a CrewAI crew with Frostbyte-powered tools."""
# Define agents with specific roles
researcher = Agent(
role="Security Researcher",
goal="Investigate domains and IPs to assess their infrastructure and security posture",
backstory="You are an experienced security researcher who analyzes web infrastructure. "
"You use IP geolocation, DNS records, and web scraping to build comprehensive profiles.",
tools=[geo_lookup, dns_lookup, scrape_url],
verbose=True,
)
analyst = Agent(
role="Crypto Market Analyst",
goal="Analyze cryptocurrency markets and compute metrics using real-time data",
backstory="You are a quantitative crypto analyst. You fetch real-time prices "
"and use code execution to calculate market metrics and ratios.",
tools=[crypto_price, run_code],
verbose=True,
)
# Define tasks
infra_task = Task(
description="Investigate the infrastructure of github.com: "
"1) Look up the IP geolocation for github.com's IP (20.205.243.166) "
"2) Check DNS records for github.com "
"3) Summarize the hosting infrastructure",
expected_output="A brief infrastructure report with IP location, DNS records summary, and hosting provider.",
agent=researcher,
)
crypto_task = Task(
description="Get the current prices of Bitcoin and Ethereum, "
"then calculate the BTC/ETH ratio and the combined market cap "
"using the code execution tool.",
expected_output="Current prices, BTC/ETH ratio, and combined market cap.",
agent=analyst,
)
# Create and run the crew
crew = Crew(
agents=[researcher, analyst],
tasks=[infra_task, crypto_task],
verbose=True,
)
result = crew.kickoff()
print("\n" + "=" * 60)
print("CREW RESULTS:")
print("=" * 60)
print(result)
if __name__ == "__main__":
if not API_KEY:
print("Get a free API key: https://ozorown.github.io")
print("Then: export FROSTBYTE_API_KEY='your-key'")
exit(1)
run_crew()