agentx-python 0.1__py3-none-any.whl → 0.2.1__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.
- agentx_python/__init__.py +2 -8
- agentx_python/agentx.py +51 -0
- agentx_python/resources/__init__.py +0 -0
- agentx_python/resources/agent.py +46 -0
- agentx_python/resources/conversation.py +63 -0
- agentx_python/util.py +5 -0
- agentx_python-0.2.1.dist-info/METADATA +71 -0
- agentx_python-0.2.1.dist-info/RECORD +12 -0
- agentx_python/agent.py +0 -55
- agentx_python-0.1.dist-info/METADATA +0 -32
- agentx_python-0.1.dist-info/RECORD +0 -8
- {agentx_python-0.1.dist-info → agentx_python-0.2.1.dist-info}/LICENSE +0 -0
- {agentx_python-0.1.dist-info → agentx_python-0.2.1.dist-info}/WHEEL +0 -0
- {agentx_python-0.1.dist-info → agentx_python-0.2.1.dist-info}/top_level.txt +0 -0
agentx_python/__init__.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import logging
|
|
2
|
-
import os
|
|
3
2
|
|
|
4
|
-
from agentx_python.
|
|
3
|
+
from agentx_python.agentx import AgentX
|
|
5
4
|
from agentx_python.version import VERSION
|
|
6
5
|
|
|
7
6
|
logging.basicConfig(
|
|
@@ -10,10 +9,5 @@ logging.basicConfig(
|
|
|
10
9
|
datefmt="%Y-%m-%d %H:%M:%S %Z",
|
|
11
10
|
)
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
api_key = os.environ.get("OPENAI_API_KEY")
|
|
15
|
-
|
|
16
|
-
Agent = Agent()
|
|
17
|
-
|
|
12
|
+
__all__ = ["AgentX"]
|
|
18
13
|
__version__ = VERSION
|
|
19
|
-
__all__ = ["api_key", "Agent"]
|
agentx_python/agentx.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
import requests
|
|
3
|
+
import os
|
|
4
|
+
import logging
|
|
5
|
+
|
|
6
|
+
from agentx_python.util import get_headers
|
|
7
|
+
from agentx_python.resources.agent import Agent
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AgentX:
|
|
11
|
+
|
|
12
|
+
def __init__(self, api_key: str = None):
|
|
13
|
+
self.api_key = api_key or os.getenv("AGENTX_API_KEY")
|
|
14
|
+
if self.api_key and not os.getenv("AGENTX_API_KEY"):
|
|
15
|
+
os.environ["AGENTX_API_KEY"] = self.api_key
|
|
16
|
+
|
|
17
|
+
def get_agent(self, id: str) -> Agent:
|
|
18
|
+
url = f"https://api.agentx.so/api/v1/access/agents/{id}"
|
|
19
|
+
# Make a GET request to the AgentX API
|
|
20
|
+
response = requests.get(url, headers=get_headers())
|
|
21
|
+
# Check if response was successful
|
|
22
|
+
if response.status_code == 200:
|
|
23
|
+
agent_res = response.json()
|
|
24
|
+
return Agent(
|
|
25
|
+
id=agent_res.get("_id"),
|
|
26
|
+
name=agent_res.get("name"),
|
|
27
|
+
avatar=agent_res.get("avatar"),
|
|
28
|
+
createdAt=agent_res.get("createdAt"),
|
|
29
|
+
updatedAt=agent_res.get("updatedAt"),
|
|
30
|
+
)
|
|
31
|
+
else:
|
|
32
|
+
raise Exception(f"Failed to retrieve agent: {response.reason}")
|
|
33
|
+
|
|
34
|
+
def list_agents(self) -> List[Agent]:
|
|
35
|
+
url = "https://api.agentx.so/api/v1/access/agents"
|
|
36
|
+
# Make a GET request to the AgentX API
|
|
37
|
+
response = requests.get(url, headers=get_headers())
|
|
38
|
+
# Check if response was successful
|
|
39
|
+
if response.status_code == 200:
|
|
40
|
+
return [
|
|
41
|
+
Agent(
|
|
42
|
+
id=agent_res.get("_id"),
|
|
43
|
+
name=agent_res.get("name"),
|
|
44
|
+
avatar=agent_res.get("avatar"),
|
|
45
|
+
createdAt=agent_res.get("createdAt"),
|
|
46
|
+
updatedAt=agent_res.get("updatedAt"),
|
|
47
|
+
)
|
|
48
|
+
for agent_res in response.json()
|
|
49
|
+
]
|
|
50
|
+
else:
|
|
51
|
+
raise Exception(f"Failed to list agents: {response.reason}")
|
|
File without changes
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from pydantic import BaseModel, Field
|
|
3
|
+
import requests
|
|
4
|
+
import os
|
|
5
|
+
import logging
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from agentx_python.util import get_headers
|
|
8
|
+
from .conversation import Conversation
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class Agent(BaseModel):
|
|
13
|
+
id: str
|
|
14
|
+
name: str
|
|
15
|
+
avatar: Optional[str]
|
|
16
|
+
createdAt: Optional[str]
|
|
17
|
+
updatedAt: Optional[str]
|
|
18
|
+
|
|
19
|
+
def __init__(self, **data):
|
|
20
|
+
super().__init__(**data)
|
|
21
|
+
|
|
22
|
+
def get_conversation(self, id: str) -> Conversation:
|
|
23
|
+
list_of_conversations = self.list_conversations()
|
|
24
|
+
return next(
|
|
25
|
+
(conv for conv in list_of_conversations if conv.id == id),
|
|
26
|
+
Exception("404 - Conversation not found"),
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
def list_conversations(self) -> List[Conversation]:
|
|
30
|
+
url = f"https://api.agentx.so/api/v1/access/agents/{self.id}/conversations"
|
|
31
|
+
response = requests.get(url, headers=get_headers())
|
|
32
|
+
if response.status_code == 200:
|
|
33
|
+
return [
|
|
34
|
+
Conversation(
|
|
35
|
+
agent_id=self.id,
|
|
36
|
+
id=conv_res.get("_id"),
|
|
37
|
+
title=conv_res.get("title"),
|
|
38
|
+
users=conv_res.get("users"),
|
|
39
|
+
agents=conv_res.get("bots"),
|
|
40
|
+
createdAt=conv_res.get("createdAt"),
|
|
41
|
+
updatedAt=conv_res.get("updatedAt"),
|
|
42
|
+
)
|
|
43
|
+
for conv_res in response.json()
|
|
44
|
+
]
|
|
45
|
+
else:
|
|
46
|
+
raise Exception(f"Failed to retrieve agent details: {response.reason}")
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from pydantic import BaseModel, Field
|
|
3
|
+
import os
|
|
4
|
+
import requests
|
|
5
|
+
from agentx_python.util import get_headers
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Conversation(BaseModel):
|
|
9
|
+
agent_id: str
|
|
10
|
+
id: str
|
|
11
|
+
title: Optional[str] = Field(default=None) # conversation customized title
|
|
12
|
+
users: List[str]
|
|
13
|
+
agents: List[str]
|
|
14
|
+
createdAt: Optional[str]
|
|
15
|
+
updatedAt: Optional[str]
|
|
16
|
+
|
|
17
|
+
def __init__(self, **data):
|
|
18
|
+
super().__init__(**data)
|
|
19
|
+
|
|
20
|
+
def generate_conversation_id(self):
|
|
21
|
+
return "generate new_conversation_id"
|
|
22
|
+
|
|
23
|
+
def list_messages(self):
|
|
24
|
+
url = f"https://api.agentx.so/api/v1/access/agents/{self.agent_id}/conversations/{self.id}"
|
|
25
|
+
response = requests.get(url, headers=get_headers())
|
|
26
|
+
if response.status_code == 200:
|
|
27
|
+
return response.json()
|
|
28
|
+
else:
|
|
29
|
+
raise Exception(
|
|
30
|
+
f"Failed to retrieve agent details: {response.status_code} - {response.reason}"
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
def chat(self, message: str, stream: bool = False, context: int = None):
|
|
34
|
+
if stream:
|
|
35
|
+
return self._chat_stream(message, context)
|
|
36
|
+
else:
|
|
37
|
+
url = f"https://api.agentx.so/api/v1/access/conversations/{self.id}/message"
|
|
38
|
+
response = requests.post(
|
|
39
|
+
url,
|
|
40
|
+
headers=get_headers(),
|
|
41
|
+
json={"message": message, "context": context},
|
|
42
|
+
)
|
|
43
|
+
return response.json()
|
|
44
|
+
|
|
45
|
+
def _chat_stream(self, message: str, context: int = None):
|
|
46
|
+
url = f"https://api.agentx.so/api/v1/access/conversations/{self.id}/messagesse"
|
|
47
|
+
response = requests.post(
|
|
48
|
+
url, headers=get_headers(), json={"message": message, "context": context}
|
|
49
|
+
)
|
|
50
|
+
if response.status_code == 200:
|
|
51
|
+
buf = b""
|
|
52
|
+
for chunk in response.iter_content():
|
|
53
|
+
buf += chunk
|
|
54
|
+
try:
|
|
55
|
+
chunk = buf.decode("utf-8")
|
|
56
|
+
yield chunk
|
|
57
|
+
except UnicodeDecodeError:
|
|
58
|
+
continue
|
|
59
|
+
buf = b""
|
|
60
|
+
else:
|
|
61
|
+
raise Exception(
|
|
62
|
+
f"Failed to send message: {response.status_code} - {response.reason}"
|
|
63
|
+
)
|
agentx_python/util.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: agentx-python
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Offical Python SDK for AgentX (https://www.agentx.so/)
|
|
5
|
+
Home-page: https://github.com/AgentX-ai/AgentX-python-sdk
|
|
6
|
+
Author: Robin Wang and AgentX Team
|
|
7
|
+
Author-email: contact@agentx.so
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: urllib3 >=1.26.11
|
|
15
|
+
Requires-Dist: certifi
|
|
16
|
+
|
|
17
|
+
# AgentX Python SDK API library
|
|
18
|
+
|
|
19
|
+
[](https://pypi.org/project/agentx-python/)
|
|
20
|
+
|
|
21
|
+
The AgentX Python SDK provides a convenient way to access to your Agent programmatically.
|
|
22
|
+
This is a python SDK for AgentX (https://www.agentx.so/)
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install --upgrade agentx-python
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
Provide an `api_key` inline or set `AGENTX_API_KEY` as an environment variable.
|
|
33
|
+
You can get an API key from https://app.agentx.so
|
|
34
|
+
|
|
35
|
+
### Agent
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
from agentx_python import AgentX
|
|
39
|
+
|
|
40
|
+
client = AgentX(api_key="<your api key here>")
|
|
41
|
+
|
|
42
|
+
# Get the list of agents you have
|
|
43
|
+
print(client.list_agents())
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Conversation
|
|
47
|
+
|
|
48
|
+
Each Conversation has `agents` and `users` tied to it.
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
# get agent
|
|
52
|
+
my_agent = client.get_agent(id="<agent id here>")
|
|
53
|
+
|
|
54
|
+
# Get the list of conversation from this agent
|
|
55
|
+
print(my_agent.list_conversations())
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Chat
|
|
59
|
+
|
|
60
|
+
A `chat` needs to happen in the conversation. You can do `stream` response too, default `False`.
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
a_conversation = my_agent.get_conversation(id="<conversation id here>")
|
|
64
|
+
|
|
65
|
+
response = a_conversation.chat("Hello, what is your name?", stream=True)
|
|
66
|
+
for chunk in response:
|
|
67
|
+
print(chunk, end="")
|
|
68
|
+
|
|
69
|
+
# output:
|
|
70
|
+
# My name is Rosita. I'm an AI assistant created by AgentX. It's nice to meet you! How can I help you today?
|
|
71
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
agentx_python/__init__.py,sha256=5VThp1fX_kBYM2afhhiTQZxcbg_kBeDiPExAH88ZPT4,293
|
|
2
|
+
agentx_python/agentx.py,sha256=D4R8cAam0LF8_PuHmAN7FXaRmrMTKsdzPdSs0HJkf6I,1873
|
|
3
|
+
agentx_python/util.py,sha256=grYAa8YTvoQSyuy4GvUOwq6SVBRr4DdrBlcTuZwQpzw,132
|
|
4
|
+
agentx_python/version.py,sha256=CpXi3jGlx23RvRyU7iytOMZrnspdWw4yofS8lpP1AJU,18
|
|
5
|
+
agentx_python/resources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
agentx_python/resources/agent.py,sha256=wpsiiYp3ZjYaonq9wL2KDrUuCnFHvrxS9xfQgaKlLrk,1528
|
|
7
|
+
agentx_python/resources/conversation.py,sha256=zpGOpSJsRTtHbeK_pizOtuGsYxpvLOUCkb-zThB0-cs,2186
|
|
8
|
+
agentx_python-0.2.1.dist-info/LICENSE,sha256=6ZbiPNFmv3xBb44LGhAa3PZYK0ROAztsd5LRFZDlGFE,1074
|
|
9
|
+
agentx_python-0.2.1.dist-info/METADATA,sha256=oJwDiWb1rt6LXftOI5fLuswBUANA9irYFFkL7jWMP1U,1851
|
|
10
|
+
agentx_python-0.2.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
11
|
+
agentx_python-0.2.1.dist-info/top_level.txt,sha256=YYLKtZsKSxhcVZ9ijHXupbsRJ7lhEjETXLwAB7lG2Y8,14
|
|
12
|
+
agentx_python-0.2.1.dist-info/RECORD,,
|
agentx_python/agent.py
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
import os
|
|
3
|
-
import logging
|
|
4
|
-
import agentx_python as agentx
|
|
5
|
-
from functools import wraps
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def api_key_check_decorator(method):
|
|
9
|
-
@wraps(method)
|
|
10
|
-
def wrapper(self, *args, **kwargs):
|
|
11
|
-
self.middleware()
|
|
12
|
-
return method(self, *args, **kwargs)
|
|
13
|
-
|
|
14
|
-
return wrapper
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class Agent:
|
|
18
|
-
|
|
19
|
-
def middleware(self):
|
|
20
|
-
self.api_key = os.getenv("AGENTX_API_KEY") or agentx.api_key
|
|
21
|
-
if not self.api_key:
|
|
22
|
-
raise Exception(
|
|
23
|
-
"No API key provided. You can set your API key in code using 'agentx.api_key = <API-KEY>', or you can set the environment variable AGENTX_API_KEY=<API-KEY>). You can generate API keys in the AgentX https://app.agentx.so."
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
@api_key_check_decorator
|
|
27
|
-
def get_agent(self, id: str):
|
|
28
|
-
url = f"https://api.agentx.so/api/v1/access/agents/{id}"
|
|
29
|
-
headers = {"accept": "*/*", "x-api-key": self.api_key}
|
|
30
|
-
|
|
31
|
-
# Make a GET request to the AgentX API
|
|
32
|
-
response = requests.get(url, headers=headers)
|
|
33
|
-
# Check if response was successful
|
|
34
|
-
if response.status_code == 200:
|
|
35
|
-
return response.json()
|
|
36
|
-
else:
|
|
37
|
-
logging.info(
|
|
38
|
-
response.json()
|
|
39
|
-
) # Print text content of response (or process it as needed)
|
|
40
|
-
raise Exception(
|
|
41
|
-
f"Failed to retrieve agent details: {response.status_code} - {response.reason}"
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
@api_key_check_decorator
|
|
45
|
-
def list_agents(self):
|
|
46
|
-
url = "https://api.agentx.so/api/v1/access/agents"
|
|
47
|
-
headers = {"accept": "*/*", "x-api-key": self.api_key}
|
|
48
|
-
|
|
49
|
-
# Make a GET request to the AgentX API
|
|
50
|
-
response = requests.get(url, headers=headers)
|
|
51
|
-
# Check if response was successful
|
|
52
|
-
if response.status_code == 200:
|
|
53
|
-
return response.json()
|
|
54
|
-
else:
|
|
55
|
-
logging.info(response.json())
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: agentx-python
|
|
3
|
-
Version: 0.1
|
|
4
|
-
Summary: Offical Python SDK for AgentX (https://www.agentx.so/)
|
|
5
|
-
Home-page: https://github.com/AgentX-ai/AgentX-python-sdk
|
|
6
|
-
Author: Robin Wang and AgentX Team
|
|
7
|
-
Author-email: contact@agentx.so
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.6
|
|
12
|
-
Description-Content-Type: text/markdown
|
|
13
|
-
License-File: LICENSE
|
|
14
|
-
Requires-Dist: urllib3 >=1.26.11
|
|
15
|
-
Requires-Dist: certifi
|
|
16
|
-
|
|
17
|
-
# AgentX Python SDK
|
|
18
|
-
|
|
19
|
-
This is a python SDK for AgentX (https://www.agentx.so/)
|
|
20
|
-
|
|
21
|
-
## Installation
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
pip install --upgrade agentx-python
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Usage
|
|
28
|
-
|
|
29
|
-
```
|
|
30
|
-
from agentx_python import agent
|
|
31
|
-
print(agent.get_agent("your-agent-id-here"))
|
|
32
|
-
```
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
agentx_python/__init__.py,sha256=eocHL3Wv7lxa7us0uYQ4yBDtbYrF38hYOsb4lS69Jk8,373
|
|
2
|
-
agentx_python/agent.py,sha256=FEA_gue4qfbm6WhrX9XZAGdx7cz7HP-clIVP6oqmB9Q,1862
|
|
3
|
-
agentx_python/version.py,sha256=CpXi3jGlx23RvRyU7iytOMZrnspdWw4yofS8lpP1AJU,18
|
|
4
|
-
agentx_python-0.1.dist-info/LICENSE,sha256=6ZbiPNFmv3xBb44LGhAa3PZYK0ROAztsd5LRFZDlGFE,1074
|
|
5
|
-
agentx_python-0.1.dist-info/METADATA,sha256=RFKPnRAs4zy11ZKe2tkxDXXAAU73Ur3eUi25zknsI_k,772
|
|
6
|
-
agentx_python-0.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
7
|
-
agentx_python-0.1.dist-info/top_level.txt,sha256=YYLKtZsKSxhcVZ9ijHXupbsRJ7lhEjETXLwAB7lG2Y8,14
|
|
8
|
-
agentx_python-0.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|