agentr 0.1.3__py3-none-any.whl → 0.1.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentr/__init__.py +1 -1
- agentr/application.py +56 -56
- agentr/applications/github/app.py +55 -51
- agentr/applications/google_calendar/app.py +73 -73
- agentr/applications/google_mail/app.py +67 -67
- agentr/applications/reddit/app.py +29 -29
- agentr/applications/resend/app.py +43 -43
- agentr/applications/tavily/app.py +57 -57
- agentr/applications/zenquotes/app.py +20 -20
- agentr/cli.py +75 -58
- agentr/exceptions.py +5 -0
- agentr/integration.py +98 -91
- agentr/server.py +105 -105
- agentr/store.py +70 -70
- agentr/test.py +37 -37
- agentr/utils/openapi.py +184 -184
- agentr-0.1.5.dist-info/METADATA +160 -0
- agentr-0.1.5.dist-info/RECORD +23 -0
- agentr-0.1.5.dist-info/licenses/LICENSE +21 -0
- agentr-0.1.3.dist-info/METADATA +0 -10
- agentr-0.1.3.dist-info/RECORD +0 -21
- {agentr-0.1.3.dist-info → agentr-0.1.5.dist-info}/WHEEL +0 -0
- {agentr-0.1.3.dist-info → agentr-0.1.5.dist-info}/entry_points.txt +0 -0
@@ -1,57 +1,57 @@
|
|
1
|
-
from agentr.application import APIApplication
|
2
|
-
from agentr.integration import Integration
|
3
|
-
|
4
|
-
class TavilyApp(APIApplication):
|
5
|
-
def __init__(self, integration: Integration) -> None:
|
6
|
-
name = "tavily"
|
7
|
-
self.base_url = "https://api.tavily.com"
|
8
|
-
super().__init__(name=name, integration=integration)
|
9
|
-
|
10
|
-
def _get_headers(self):
|
11
|
-
credentials = self.integration.get_credentials()
|
12
|
-
if not credentials:
|
13
|
-
raise ValueError("No credentials found")
|
14
|
-
return {
|
15
|
-
"Authorization": f"Bearer {credentials['api_key']}",
|
16
|
-
"Content-Type": "application/json"
|
17
|
-
}
|
18
|
-
|
19
|
-
def search(self, query: str) -> str:
|
20
|
-
"""Search the web using Tavily's search API
|
21
|
-
|
22
|
-
Args:
|
23
|
-
query: The search query
|
24
|
-
|
25
|
-
Returns:
|
26
|
-
str: A summary of search results
|
27
|
-
"""
|
28
|
-
self.validate()
|
29
|
-
url = f"{self.base_url}/search"
|
30
|
-
payload = {
|
31
|
-
"query": query,
|
32
|
-
"topic": "general",
|
33
|
-
"search_depth": "basic",
|
34
|
-
"max_results": 3,
|
35
|
-
"include_answer": True,
|
36
|
-
"include_raw_content": False,
|
37
|
-
"include_images": False,
|
38
|
-
"include_image_descriptions": False,
|
39
|
-
"include_domains": [],
|
40
|
-
"exclude_domains": []
|
41
|
-
}
|
42
|
-
|
43
|
-
response = self._post(url, payload)
|
44
|
-
result = response.json()
|
45
|
-
|
46
|
-
if "answer" in result:
|
47
|
-
return result["answer"]
|
48
|
-
|
49
|
-
# Fallback to combining top results if no direct answer
|
50
|
-
summaries = []
|
51
|
-
for item in result.get("results", [])[:3]:
|
52
|
-
summaries.append(f"• {item['title']}: {item['snippet']}")
|
53
|
-
|
54
|
-
return "\n".join(summaries)
|
55
|
-
|
56
|
-
def list_tools(self):
|
57
|
-
return [self.search]
|
1
|
+
from agentr.application import APIApplication
|
2
|
+
from agentr.integration import Integration
|
3
|
+
|
4
|
+
class TavilyApp(APIApplication):
|
5
|
+
def __init__(self, integration: Integration) -> None:
|
6
|
+
name = "tavily"
|
7
|
+
self.base_url = "https://api.tavily.com"
|
8
|
+
super().__init__(name=name, integration=integration)
|
9
|
+
|
10
|
+
def _get_headers(self):
|
11
|
+
credentials = self.integration.get_credentials()
|
12
|
+
if not credentials:
|
13
|
+
raise ValueError("No credentials found")
|
14
|
+
return {
|
15
|
+
"Authorization": f"Bearer {credentials['api_key']}",
|
16
|
+
"Content-Type": "application/json"
|
17
|
+
}
|
18
|
+
|
19
|
+
def search(self, query: str) -> str:
|
20
|
+
"""Search the web using Tavily's search API
|
21
|
+
|
22
|
+
Args:
|
23
|
+
query: The search query
|
24
|
+
|
25
|
+
Returns:
|
26
|
+
str: A summary of search results
|
27
|
+
"""
|
28
|
+
self.validate()
|
29
|
+
url = f"{self.base_url}/search"
|
30
|
+
payload = {
|
31
|
+
"query": query,
|
32
|
+
"topic": "general",
|
33
|
+
"search_depth": "basic",
|
34
|
+
"max_results": 3,
|
35
|
+
"include_answer": True,
|
36
|
+
"include_raw_content": False,
|
37
|
+
"include_images": False,
|
38
|
+
"include_image_descriptions": False,
|
39
|
+
"include_domains": [],
|
40
|
+
"exclude_domains": []
|
41
|
+
}
|
42
|
+
|
43
|
+
response = self._post(url, payload)
|
44
|
+
result = response.json()
|
45
|
+
|
46
|
+
if "answer" in result:
|
47
|
+
return result["answer"]
|
48
|
+
|
49
|
+
# Fallback to combining top results if no direct answer
|
50
|
+
summaries = []
|
51
|
+
for item in result.get("results", [])[:3]:
|
52
|
+
summaries.append(f"• {item['title']}: {item['snippet']}")
|
53
|
+
|
54
|
+
return "\n".join(summaries)
|
55
|
+
|
56
|
+
def list_tools(self):
|
57
|
+
return [self.search]
|
@@ -1,21 +1,21 @@
|
|
1
|
-
from agentr.application import APIApplication
|
2
|
-
|
3
|
-
|
4
|
-
class ZenQuoteApp(APIApplication):
|
5
|
-
def __init__(self, **kwargs) -> None:
|
6
|
-
super().__init__(name="zenquote", **kwargs)
|
7
|
-
|
8
|
-
def get_quote(self) -> str:
|
9
|
-
"""Get an inspirational quote from the Zen Quotes API
|
10
|
-
|
11
|
-
Returns:
|
12
|
-
A random inspirational quote
|
13
|
-
"""
|
14
|
-
url = "https://zenquotes.io/api/random"
|
15
|
-
response = self._get(url)
|
16
|
-
data = response.json()
|
17
|
-
quote_data = data[0]
|
18
|
-
return f"{quote_data['q']} - {quote_data['a']}"
|
19
|
-
|
20
|
-
def list_tools(self):
|
1
|
+
from agentr.application import APIApplication
|
2
|
+
|
3
|
+
|
4
|
+
class ZenQuoteApp(APIApplication):
|
5
|
+
def __init__(self, **kwargs) -> None:
|
6
|
+
super().__init__(name="zenquote", **kwargs)
|
7
|
+
|
8
|
+
def get_quote(self) -> str:
|
9
|
+
"""Get an inspirational quote from the Zen Quotes API
|
10
|
+
|
11
|
+
Returns:
|
12
|
+
A random inspirational quote
|
13
|
+
"""
|
14
|
+
url = "https://zenquotes.io/api/random"
|
15
|
+
response = self._get(url)
|
16
|
+
data = response.json()
|
17
|
+
quote_data = data[0]
|
18
|
+
return f"{quote_data['q']} - {quote_data['a']}"
|
19
|
+
|
20
|
+
def list_tools(self):
|
21
21
|
return [self.get_quote]
|
agentr/cli.py
CHANGED
@@ -1,58 +1,75 @@
|
|
1
|
-
import typer
|
2
|
-
from pathlib import Path
|
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
|
-
mcp
|
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
|
-
|
1
|
+
import typer
|
2
|
+
from pathlib import Path
|
3
|
+
import sys
|
4
|
+
|
5
|
+
app = typer.Typer()
|
6
|
+
|
7
|
+
@app.command()
|
8
|
+
def version():
|
9
|
+
"""Show the version of the CLI"""
|
10
|
+
print("agentr version 0.1.0")
|
11
|
+
|
12
|
+
@app.command()
|
13
|
+
def generate(schema_path: Path = typer.Option(..., "--schema", "-s")):
|
14
|
+
"""Generate API client from OpenAPI schema"""
|
15
|
+
if not schema_path.exists():
|
16
|
+
typer.echo(f"Error: Schema file {schema_path} does not exist", err=True)
|
17
|
+
raise typer.Exit(1)
|
18
|
+
from .utils.openapi import generate_api_client, load_schema
|
19
|
+
|
20
|
+
try:
|
21
|
+
schema = load_schema(schema_path)
|
22
|
+
except Exception as e:
|
23
|
+
typer.echo(f"Error loading schema: {e}", err=True)
|
24
|
+
raise typer.Exit(1)
|
25
|
+
code = generate_api_client(schema)
|
26
|
+
print(code)
|
27
|
+
|
28
|
+
@app.command()
|
29
|
+
def run():
|
30
|
+
"""Run the MCP server"""
|
31
|
+
from agentr.test import mcp
|
32
|
+
mcp.run()
|
33
|
+
|
34
|
+
@app.command()
|
35
|
+
def install(app_name: str):
|
36
|
+
"""Install an app"""
|
37
|
+
import json
|
38
|
+
|
39
|
+
# Print instructions before asking for API key
|
40
|
+
typer.echo("╭─ Instruction ─────────────────────────────────────────────────────────────────╮")
|
41
|
+
typer.echo("│ API key is required. Visit https://agentr.dev to create an API key. │")
|
42
|
+
typer.echo("╰───────────────────────────────────────────────────────────────────────────────╯")
|
43
|
+
# Prompt for API key
|
44
|
+
api_key = typer.prompt("Enter your AgentR API key", hide_input=True)
|
45
|
+
|
46
|
+
if app_name == "claude":
|
47
|
+
typer.echo(f"Installing mcp server for: {app_name}")
|
48
|
+
|
49
|
+
# Determine platform-specific config path
|
50
|
+
if sys.platform == "darwin": # macOS
|
51
|
+
config_path = Path.home() / "Library/Application Support/Claude/claude_desktop_config.json"
|
52
|
+
elif sys.platform == "win32": # Windows
|
53
|
+
config_path = Path.home() / "AppData/Roaming/Claude/claude_desktop_config.json"
|
54
|
+
else:
|
55
|
+
typer.echo("Unsupported platform. Only macOS and Windows are currently supported.", err=True)
|
56
|
+
raise typer.Exit(1)
|
57
|
+
|
58
|
+
|
59
|
+
with open(config_path, 'r') as f:
|
60
|
+
config = json.load(f)
|
61
|
+
config['mcpServers']['agentr-r'] = {
|
62
|
+
"command": "uvx",
|
63
|
+
"args": ["agentr@latest", "run"],
|
64
|
+
"env": {
|
65
|
+
"AGENTR_API_KEY": api_key
|
66
|
+
}
|
67
|
+
}
|
68
|
+
with open(config_path, 'w') as f:
|
69
|
+
json.dump(config, f, indent=4)
|
70
|
+
typer.echo("App installed successfully")
|
71
|
+
else:
|
72
|
+
typer.echo(f"App {app_name} not supported")
|
73
|
+
|
74
|
+
if __name__ == "__main__":
|
75
|
+
app()
|
agentr/exceptions.py
ADDED
agentr/integration.py
CHANGED
@@ -1,91 +1,98 @@
|
|
1
|
-
from abc import ABC, abstractmethod
|
2
|
-
import os
|
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
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
def
|
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
|
-
def
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
1
|
+
from abc import ABC, abstractmethod
|
2
|
+
import os
|
3
|
+
import sys
|
4
|
+
|
5
|
+
from loguru import logger
|
6
|
+
from agentr.store import Store
|
7
|
+
import httpx
|
8
|
+
|
9
|
+
"""
|
10
|
+
Integration defines how a Application needs to authorize.
|
11
|
+
It is responsible for authenticating application with the service provider.
|
12
|
+
Supported integrations:
|
13
|
+
- AgentR Integration
|
14
|
+
- API Key Integration
|
15
|
+
"""
|
16
|
+
|
17
|
+
class Integration(ABC):
|
18
|
+
def __init__(self, name: str, store: Store = None):
|
19
|
+
self.name = name
|
20
|
+
self.store = store
|
21
|
+
|
22
|
+
@abstractmethod
|
23
|
+
def get_credentials(self):
|
24
|
+
pass
|
25
|
+
|
26
|
+
@abstractmethod
|
27
|
+
def set_credentials(self, credentials: dict):
|
28
|
+
pass
|
29
|
+
|
30
|
+
class ApiKeyIntegration(Integration):
|
31
|
+
def __init__(self, name: str, store: Store = None, **kwargs):
|
32
|
+
super().__init__(name, store, **kwargs)
|
33
|
+
|
34
|
+
def get_credentials(self):
|
35
|
+
credentials = self.store.get(self.name)
|
36
|
+
return credentials
|
37
|
+
|
38
|
+
def set_credentials(self, credentials: dict):
|
39
|
+
self.store.set(self.name, credentials)
|
40
|
+
|
41
|
+
def authorize(self):
|
42
|
+
return {"text": "Please configure the environment variable {self.name}_API_KEY"}
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
class AgentRIntegration(Integration):
|
47
|
+
def __init__(self, name: str, api_key: str = None, **kwargs):
|
48
|
+
super().__init__(name, **kwargs)
|
49
|
+
self.api_key = api_key or os.getenv("AGENTR_API_KEY")
|
50
|
+
if not self.api_key:
|
51
|
+
logger.error("API key for AgentR is missing. Please visit https://agentr.dev to create an API key, then set it as AGENTR_API_KEY environment variable.")
|
52
|
+
raise ValueError("AgentR API key required - get one at https://agentr.dev")
|
53
|
+
|
54
|
+
self.base_url = "https://auth.agentr.dev"
|
55
|
+
self.user_id = "default"
|
56
|
+
|
57
|
+
def _create_session_token(self):
|
58
|
+
url = "https://auth.agentr.dev/connect/sessions"
|
59
|
+
body = {
|
60
|
+
"end_user": {
|
61
|
+
"id": self.user_id,
|
62
|
+
},
|
63
|
+
"allowed_integrations": [self.name]
|
64
|
+
}
|
65
|
+
response = httpx.post(url, headers={"Authorization": f"Bearer {self.api_key}"}, json=body)
|
66
|
+
data = response.json()
|
67
|
+
print(data)
|
68
|
+
return data["data"]["token"]
|
69
|
+
|
70
|
+
def _get_authorize_url(self):
|
71
|
+
session_token = self._create_session_token()
|
72
|
+
return f"https://auth.agentr.dev/oauth/connect/{self.name}?connect_session_token={session_token}"
|
73
|
+
|
74
|
+
def get_connection_by_owner(self):
|
75
|
+
url = f"https://auth.agentr.dev/connection?endUserId={self.user_id}"
|
76
|
+
response = httpx.get(url, headers={"Authorization": f"Bearer {self.api_key}"})
|
77
|
+
if response.status_code == 200:
|
78
|
+
connections = response.json()["connections"]
|
79
|
+
for connection in connections:
|
80
|
+
if connection["provider_config_key"] == self.name:
|
81
|
+
return connection["connection_id"]
|
82
|
+
return None
|
83
|
+
|
84
|
+
def set_credentials(self, credentials: dict):
|
85
|
+
raise NotImplementedError("AgentR Integration does not support setting credentials. Visit the authorize url to set credentials.")
|
86
|
+
|
87
|
+
def get_credentials(self):
|
88
|
+
connection_id = self.get_connection_by_owner()
|
89
|
+
logger.info(f"Connection ID: {connection_id}")
|
90
|
+
if connection_id:
|
91
|
+
response = httpx.get(f"{self.base_url}/connection/{connection_id}?provider_config_key={self.name}", headers={"Authorization": f"Bearer {self.api_key}"})
|
92
|
+
data = response.json()
|
93
|
+
return data.get("credentials")
|
94
|
+
return None
|
95
|
+
|
96
|
+
def authorize(self):
|
97
|
+
url = self._get_authorize_url()
|
98
|
+
return f"Please authorize the application by clicking the link {url}"
|