agentx-python 0.2.1__tar.gz → 0.3.1__tar.gz

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.
Files changed (21) hide show
  1. {agentx-python-0.2.1 → agentx_python-0.3.1}/PKG-INFO +16 -5
  2. {agentx-python-0.2.1 → agentx_python-0.3.1}/README.md +3 -3
  3. {agentx-python-0.2.1/agentx_python → agentx_python-0.3.1/agentx}/__init__.py +2 -2
  4. {agentx-python-0.2.1/agentx_python → agentx_python-0.3.1/agentx}/agentx.py +2 -2
  5. {agentx-python-0.2.1/agentx_python → agentx_python-0.3.1/agentx}/resources/agent.py +1 -1
  6. agentx_python-0.3.1/agentx/resources/conversation.py +128 -0
  7. agentx_python-0.3.1/agentx/version.py +1 -0
  8. {agentx-python-0.2.1 → agentx_python-0.3.1}/agentx_python.egg-info/PKG-INFO +16 -5
  9. agentx_python-0.3.1/agentx_python.egg-info/SOURCES.txt +15 -0
  10. agentx_python-0.3.1/agentx_python.egg-info/top_level.txt +1 -0
  11. {agentx-python-0.2.1 → agentx_python-0.3.1}/setup.py +1 -1
  12. agentx-python-0.2.1/agentx_python/resources/conversation.py +0 -63
  13. agentx-python-0.2.1/agentx_python/version.py +0 -1
  14. agentx-python-0.2.1/agentx_python.egg-info/SOURCES.txt +0 -15
  15. agentx-python-0.2.1/agentx_python.egg-info/top_level.txt +0 -1
  16. {agentx-python-0.2.1 → agentx_python-0.3.1}/LICENSE +0 -0
  17. {agentx-python-0.2.1/agentx_python → agentx_python-0.3.1/agentx}/resources/__init__.py +0 -0
  18. {agentx-python-0.2.1/agentx_python → agentx_python-0.3.1/agentx}/util.py +0 -0
  19. {agentx-python-0.2.1 → agentx_python-0.3.1}/agentx_python.egg-info/dependency_links.txt +0 -0
  20. {agentx-python-0.2.1 → agentx_python-0.3.1}/agentx_python.egg-info/requires.txt +0 -0
  21. {agentx-python-0.2.1 → agentx_python-0.3.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: agentx-python
3
- Version: 0.2.1
3
+ Version: 0.3.1
4
4
  Summary: Offical Python SDK for AgentX (https://www.agentx.so/)
5
5
  Home-page: https://github.com/AgentX-ai/AgentX-python-sdk
6
6
  Author: Robin Wang and AgentX Team
@@ -11,6 +11,17 @@ Classifier: Operating System :: OS Independent
11
11
  Requires-Python: >=3.6
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
+ Requires-Dist: urllib3>=1.26.11
15
+ Requires-Dist: certifi
16
+ Dynamic: author
17
+ Dynamic: author-email
18
+ Dynamic: classifier
19
+ Dynamic: description
20
+ Dynamic: description-content-type
21
+ Dynamic: home-page
22
+ Dynamic: requires-dist
23
+ Dynamic: requires-python
24
+ Dynamic: summary
14
25
 
15
26
  # AgentX Python SDK API library
16
27
 
@@ -32,7 +43,7 @@ You can get an API key from https://app.agentx.so
32
43
 
33
44
  ### Agent
34
45
 
35
- ```
46
+ ```python
36
47
  from agentx_python import AgentX
37
48
 
38
49
  client = AgentX(api_key="<your api key here>")
@@ -45,7 +56,7 @@ print(client.list_agents())
45
56
 
46
57
  Each Conversation has `agents` and `users` tied to it.
47
58
 
48
- ```
59
+ ```python
49
60
  # get agent
50
61
  my_agent = client.get_agent(id="<agent id here>")
51
62
 
@@ -57,7 +68,7 @@ print(my_agent.list_conversations())
57
68
 
58
69
  A `chat` needs to happen in the conversation. You can do `stream` response too, default `False`.
59
70
 
60
- ```
71
+ ```python
61
72
  a_conversation = my_agent.get_conversation(id="<conversation id here>")
62
73
 
63
74
  response = a_conversation.chat("Hello, what is your name?", stream=True)
@@ -18,7 +18,7 @@ You can get an API key from https://app.agentx.so
18
18
 
19
19
  ### Agent
20
20
 
21
- ```
21
+ ```python
22
22
  from agentx_python import AgentX
23
23
 
24
24
  client = AgentX(api_key="<your api key here>")
@@ -31,7 +31,7 @@ print(client.list_agents())
31
31
 
32
32
  Each Conversation has `agents` and `users` tied to it.
33
33
 
34
- ```
34
+ ```python
35
35
  # get agent
36
36
  my_agent = client.get_agent(id="<agent id here>")
37
37
 
@@ -43,7 +43,7 @@ print(my_agent.list_conversations())
43
43
 
44
44
  A `chat` needs to happen in the conversation. You can do `stream` response too, default `False`.
45
45
 
46
- ```
46
+ ```python
47
47
  a_conversation = my_agent.get_conversation(id="<conversation id here>")
48
48
 
49
49
  response = a_conversation.chat("Hello, what is your name?", stream=True)
@@ -1,7 +1,7 @@
1
1
  import logging
2
2
 
3
- from agentx_python.agentx import AgentX
4
- from agentx_python.version import VERSION
3
+ from agentx.agentx import AgentX
4
+ from agentx.version import VERSION
5
5
 
6
6
  logging.basicConfig(
7
7
  level=logging.INFO,
@@ -3,8 +3,8 @@ import requests
3
3
  import os
4
4
  import logging
5
5
 
6
- from agentx_python.util import get_headers
7
- from agentx_python.resources.agent import Agent
6
+ from agentx.util import get_headers
7
+ from agentx.resources.agent import Agent
8
8
 
9
9
 
10
10
  class AgentX:
@@ -4,7 +4,7 @@ import requests
4
4
  import os
5
5
  import logging
6
6
  from dataclasses import dataclass
7
- from agentx_python.util import get_headers
7
+ from agentx.util import get_headers
8
8
  from .conversation import Conversation
9
9
 
10
10
 
@@ -0,0 +1,128 @@
1
+ import json
2
+ import requests
3
+ from typing import Optional, List, Any, Iterator
4
+ from pydantic import BaseModel, Field
5
+ from agentx.util import get_headers
6
+
7
+
8
+ class ChatResponse(BaseModel):
9
+ text: str | None
10
+ cot: str | None
11
+ botId: str
12
+ reference: Optional[Any]
13
+ tasks: Optional[Any]
14
+
15
+
16
+ class Message(BaseModel):
17
+ id: str = Field(alias="_id")
18
+ conversationId: str
19
+ role: str # user or bot
20
+ botId: Optional[str] = Field(alias="bot", default=None)
21
+ userId: Optional[str] = Field(alias="user", default=None)
22
+ text: str | None
23
+ cot: str | None
24
+ createdAt: str
25
+ updatedAt: str
26
+
27
+ class Config:
28
+ populate_by_name = True
29
+ extra = "ignore"
30
+
31
+
32
+ class Conversation(BaseModel):
33
+ agent_id: str
34
+ id: str = Field(alias="_id")
35
+ title: Optional[str] = Field(default=None) # conversation customized title
36
+ users: List[str]
37
+ agents: List[str] = Field(alias="bots")
38
+ createdAt: Optional[str]
39
+ updatedAt: Optional[str]
40
+
41
+ class Config:
42
+ populate_by_name = True
43
+ extra = "ignore"
44
+
45
+ def __init__(self, **data):
46
+ super().__init__(**data)
47
+
48
+ def new_conversation(self) -> "Conversation":
49
+ url = f"https://api.agentx.so/api/v1/access/agents/{self.agent_id}/conversations/new"
50
+ response = requests.post(
51
+ url,
52
+ headers=get_headers(),
53
+ json={"type": "chat"},
54
+ )
55
+ if response.status_code == 200:
56
+ new_conv = response.json()
57
+ new_conv["agent_id"] = self.agent_id
58
+ return Conversation(**new_conv)
59
+ else:
60
+ raise Exception(
61
+ f"Failed to create new conversation: {response.status_code} - {response.reason}"
62
+ )
63
+
64
+ def list_messages(self) -> List[Message]:
65
+ url = f"https://api.agentx.so/api/v1/access/agents/{self.agent_id}/conversations/{self.id}"
66
+ response = requests.get(url, headers=get_headers())
67
+ if response.status_code == 200:
68
+ res = response.json()
69
+ if res.get("messages"):
70
+ message_list = []
71
+ for message in res["messages"]:
72
+ if message.get("bot"):
73
+ message["role"] = "bot"
74
+ else:
75
+ message["role"] = "user"
76
+ message_list.append(Message(**message))
77
+ return message_list
78
+ else:
79
+ raise Exception("No messages found in the conversation.")
80
+ else:
81
+ raise Exception(
82
+ f"Failed to retrieve agent details: {response.status_code} - {response.reason}"
83
+ )
84
+
85
+ def chat(self, message: str, context: int = None):
86
+ url = f"https://api.agentx.so/api/v1/access/conversations/{self.id}/message"
87
+ response = requests.post(
88
+ url,
89
+ headers=get_headers(),
90
+ json={"message": message, "context": context},
91
+ )
92
+ return response.json()
93
+
94
+ def chat_stream(self, message: str, context: int = None) -> Iterator[ChatResponse]:
95
+ url = f"https://api.agentx.so/api/v1/access/conversations/{self.id}/jsonmessagesse"
96
+ response = requests.post(
97
+ url, headers=get_headers(), json={"message": message, "context": context}
98
+ )
99
+ result = ""
100
+ if response.status_code == 200:
101
+ buf = b""
102
+ for chunk in response.iter_content():
103
+ buf += chunk
104
+ try:
105
+ chunk = buf.decode("utf-8")
106
+ # yield chunk
107
+ except UnicodeDecodeError:
108
+ continue
109
+ result += chunk
110
+ buf = b""
111
+ try:
112
+ if result.count("{") == result.count("}"):
113
+ catch_json = json.loads(result)
114
+ if catch_json:
115
+ result = ""
116
+ yield ChatResponse(
117
+ text=catch_json.get("text"),
118
+ cot=catch_json.get("cot"),
119
+ botId=catch_json.get("botId"),
120
+ reference=catch_json.get("reference"),
121
+ tasks=catch_json.get("tasks"),
122
+ )
123
+ except json.JSONDecodeError:
124
+ continue
125
+ else:
126
+ raise Exception(
127
+ f"Failed to send message: {response.status_code} - {response.reason}"
128
+ )
@@ -0,0 +1 @@
1
+ VERSION = "0.3.0"
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: agentx-python
3
- Version: 0.2.1
3
+ Version: 0.3.1
4
4
  Summary: Offical Python SDK for AgentX (https://www.agentx.so/)
5
5
  Home-page: https://github.com/AgentX-ai/AgentX-python-sdk
6
6
  Author: Robin Wang and AgentX Team
@@ -11,6 +11,17 @@ Classifier: Operating System :: OS Independent
11
11
  Requires-Python: >=3.6
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
+ Requires-Dist: urllib3>=1.26.11
15
+ Requires-Dist: certifi
16
+ Dynamic: author
17
+ Dynamic: author-email
18
+ Dynamic: classifier
19
+ Dynamic: description
20
+ Dynamic: description-content-type
21
+ Dynamic: home-page
22
+ Dynamic: requires-dist
23
+ Dynamic: requires-python
24
+ Dynamic: summary
14
25
 
15
26
  # AgentX Python SDK API library
16
27
 
@@ -32,7 +43,7 @@ You can get an API key from https://app.agentx.so
32
43
 
33
44
  ### Agent
34
45
 
35
- ```
46
+ ```python
36
47
  from agentx_python import AgentX
37
48
 
38
49
  client = AgentX(api_key="<your api key here>")
@@ -45,7 +56,7 @@ print(client.list_agents())
45
56
 
46
57
  Each Conversation has `agents` and `users` tied to it.
47
58
 
48
- ```
59
+ ```python
49
60
  # get agent
50
61
  my_agent = client.get_agent(id="<agent id here>")
51
62
 
@@ -57,7 +68,7 @@ print(my_agent.list_conversations())
57
68
 
58
69
  A `chat` needs to happen in the conversation. You can do `stream` response too, default `False`.
59
70
 
60
- ```
71
+ ```python
61
72
  a_conversation = my_agent.get_conversation(id="<conversation id here>")
62
73
 
63
74
  response = a_conversation.chat("Hello, what is your name?", stream=True)
@@ -0,0 +1,15 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ agentx/__init__.py
5
+ agentx/agentx.py
6
+ agentx/util.py
7
+ agentx/version.py
8
+ agentx/resources/__init__.py
9
+ agentx/resources/agent.py
10
+ agentx/resources/conversation.py
11
+ agentx_python.egg-info/PKG-INFO
12
+ agentx_python.egg-info/SOURCES.txt
13
+ agentx_python.egg-info/dependency_links.txt
14
+ agentx_python.egg-info/requires.txt
15
+ agentx_python.egg-info/top_level.txt
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="agentx-python",
5
- version="0.2.1", # Update this version number each time you make a release
5
+ version="0.3.1", # Update this version number each time you make a release
6
6
  packages=find_packages(),
7
7
  install_requires=[
8
8
  "urllib3>=1.26.11",
@@ -1,63 +0,0 @@
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
- )
@@ -1 +0,0 @@
1
- VERSION = "0.1.0"
@@ -1,15 +0,0 @@
1
- LICENSE
2
- README.md
3
- setup.py
4
- agentx_python/__init__.py
5
- agentx_python/agentx.py
6
- agentx_python/util.py
7
- agentx_python/version.py
8
- agentx_python.egg-info/PKG-INFO
9
- agentx_python.egg-info/SOURCES.txt
10
- agentx_python.egg-info/dependency_links.txt
11
- agentx_python.egg-info/requires.txt
12
- agentx_python.egg-info/top_level.txt
13
- agentx_python/resources/__init__.py
14
- agentx_python/resources/agent.py
15
- agentx_python/resources/conversation.py
@@ -1 +0,0 @@
1
- agentx_python
File without changes
File without changes