Skip to content

Commit bef3fec

Browse files
authored
Resources Agents (#442)
* resources * Tests * version * lint * Update requirements.txt
1 parent eef879c commit bef3fec

8 files changed

Lines changed: 216 additions & 2 deletions

File tree

cuenca/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
__all__ = [
22
'__version__',
3+
'Agent',
4+
'AgentVerification',
35
'ApiKey',
46
'Account',
57
'Arpc',
@@ -53,6 +55,8 @@
5355
from . import http
5456
from .resources import (
5557
Account,
58+
Agent,
59+
AgentVerification,
5660
ApiKey,
5761
Arpc,
5862
BalanceEntry,

cuenca/resources/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
__all__ = [
2+
'Agent',
3+
'AgentVerification',
24
'ApiKey',
35
'Account',
46
'Arpc',
@@ -47,6 +49,8 @@
4749
]
4850

4951
from .accounts import Account
52+
from .agent_verifications import AgentVerification
53+
from .agents import Agent
5054
from .api_keys import ApiKey
5155
from .arpc import Arpc
5256
from .balance_entries import BalanceEntry
@@ -96,6 +100,8 @@
96100

97101
# avoid circular imports
98102
resource_classes = [
103+
Agent,
104+
AgentVerification,
99105
ApiKey,
100106
Account,
101107
Arpc,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import datetime as dt
2+
from typing import ClassVar
3+
4+
from cuenca_validations.types.identities import PhoneNumber
5+
from pydantic import ConfigDict
6+
7+
from ..http import Session, session as global_session
8+
from .base import Creatable
9+
10+
11+
class AgentVerification(Creatable):
12+
_resource: ClassVar = 'agent_verifications'
13+
14+
created_at: dt.datetime
15+
user_id: str
16+
platform_id: str
17+
phone_number: PhoneNumber
18+
pairing_code: str
19+
deactivated_at: dt.datetime
20+
21+
model_config = ConfigDict(
22+
json_schema_extra={
23+
'example': {
24+
'id': 'AVjTtPH1mhT65GEgOeomJ4DQ',
25+
'created_at': '2026-06-25T22:50:08.495768',
26+
'user_id': 'USMP3EPgI4T4CPFyVmXUPi8A',
27+
'platform_id': 'PTZbBlk__kQt-wfwzP5nwA9A',
28+
'phone_number': '+525512345678',
29+
'pairing_code': 'OJC37W',
30+
'deactivated_at': '2026-06-25T22:55:08.495779',
31+
}
32+
}
33+
)
34+
35+
@classmethod
36+
def create(cls, session: Session = global_session) -> 'AgentVerification':
37+
return cls._create(session=session)

cuenca/resources/agents.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import datetime as dt
2+
from typing import ClassVar, Optional
3+
4+
from cuenca_validations.types import AgentQuery, AgentRequest, PhoneNumber
5+
from cuenca_validations.typing import DictStrAny
6+
from pydantic import ConfigDict, Field
7+
8+
from ..http import Session, session as global_session
9+
from .base import Creatable, Queryable
10+
11+
12+
class Agent(Creatable, Queryable):
13+
_resource: ClassVar = 'agents'
14+
_query_params: ClassVar = AgentQuery
15+
16+
created_at: dt.datetime
17+
user_id: str
18+
platform_id: str
19+
agent_verification_id: str
20+
session_id: str
21+
device_info: DictStrAny = Field(default_factory=dict)
22+
deactivated_at: Optional[dt.datetime] = None
23+
24+
model_config = ConfigDict(
25+
json_schema_extra={
26+
'example': {
27+
'id': 'AG1G6Bm0oGQOCRjTDaeFSsyA',
28+
'created_at': '2026-06-27T01:56:42.613781',
29+
'user_id': 'USMP3EPgI4T4CPFyVmXUPi8A',
30+
'platform_id': 'PTZbBlk__kQt-wfwzP5nwA9A',
31+
'agent_verification_id': 'AV7A1FLC7MSnqKcb7oAkiQxA',
32+
'session_id': 'SSH0M5yteyRHas-PmfT9pu9w',
33+
'device_info': {'client': 'cursor', 'os': 'macOS'},
34+
}
35+
}
36+
)
37+
38+
@classmethod
39+
def create(
40+
cls,
41+
pairing_code: str,
42+
phone_number: PhoneNumber,
43+
device_info: Optional[DictStrAny] = None,
44+
*,
45+
session: Session = global_session,
46+
) -> 'Agent':
47+
req = AgentRequest(
48+
pairing_code=pairing_code,
49+
phone_number=phone_number,
50+
device_info=device_info or {},
51+
)
52+
return cls._create(session=session, **req.model_dump())

cuenca/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = '2.2.1'
1+
__version__ = '2.2.2'
22
CLIENT_VERSION = __version__
33
API_VERSION = '2020-03-19'

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
requests==2.32.3
2-
cuenca-validations==2.1.34
2+
cuenca-validations==2.1.39
33
pydantic-extra-types==2.10.2
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
interactions:
2+
- request:
3+
body: '{}'
4+
headers:
5+
Authorization:
6+
- DUMMY
7+
Content-Length:
8+
- '2'
9+
Content-Type:
10+
- application/json
11+
User-Agent:
12+
- cuenca-python/2.2.2.dev0
13+
X-Cuenca-Api-Version:
14+
- '2020-03-19'
15+
X-Cuenca-LoginId:
16+
- DUMMY
17+
method: POST
18+
uri: https://sandbox.cuenca.com/agent_verifications
19+
response:
20+
body:
21+
string: '{"id":"AVGrMmja4vRpCs1L7q5oZaGg","created_at":"2026-06-29T21:12:29.455175","user_id":"USMP3EPgI4T4CPFyVmXUPi8A","platform_id":"PTZbBlk__kQt-wfwzP5nwA9A","phone_number":"+525520902020","pairing_code":"E89U5U","deactivated_at":"2026-06-29T21:17:29.455186"}'
22+
headers:
23+
Connection:
24+
- keep-alive
25+
Content-Length:
26+
- '254'
27+
Content-Type:
28+
- application/json
29+
Date:
30+
- Mon, 29 Jun 2026 21:12:29 GMT
31+
X-Request-Time:
32+
- 'value: 0.433'
33+
x-amz-apigw-id:
34+
- fvjWTGVvCYcEcIQ=
35+
x-amzn-Remapped-Connection:
36+
- keep-alive
37+
x-amzn-Remapped-Content-Length:
38+
- '254'
39+
x-amzn-Remapped-Date:
40+
- Mon, 29 Jun 2026 21:12:29 GMT
41+
x-amzn-Remapped-Server:
42+
- nginx/1.30.3
43+
x-amzn-RequestId:
44+
- e418d89f-5e4f-4540-8334-d81914362ad9
45+
status:
46+
code: 201
47+
message: Created
48+
- request:
49+
body: '{"pairing_code": "E89U5U", "phone_number": "+525520902020", "device_info":
50+
{"client": "cursor", "os": "macOS"}}'
51+
headers:
52+
Authorization:
53+
- DUMMY
54+
Content-Length:
55+
- '111'
56+
Content-Type:
57+
- application/json
58+
User-Agent:
59+
- cuenca-python/2.2.2.dev0
60+
X-Cuenca-Api-Version:
61+
- '2020-03-19'
62+
method: POST
63+
uri: https://sandbox.cuenca.com/agents
64+
response:
65+
body:
66+
string: '{"id":"AG7eGV9zSIR92V7fNKnM57UA","created_at":"2026-06-29T21:12:34.918228","user_id":"USMP3EPgI4T4CPFyVmXUPi8A","platform_id":"PTZbBlk__kQt-wfwzP5nwA9A","agent_verification_id":"AVGrMmja4vRpCs1L7q5oZaGg","session_id":"SSHdQzltPgQByBqJYGXcBJUg","device_info":{}}'
67+
headers:
68+
Connection:
69+
- keep-alive
70+
Content-Length:
71+
- '261'
72+
Content-Type:
73+
- application/json
74+
Date:
75+
- Mon, 29 Jun 2026 21:12:34 GMT
76+
X-Request-Time:
77+
- 'value: 0.283'
78+
x-amz-apigw-id:
79+
- fvjWeF6iiYcEGYw=
80+
x-amzn-Remapped-Connection:
81+
- keep-alive
82+
x-amzn-Remapped-Content-Length:
83+
- '261'
84+
x-amzn-Remapped-Date:
85+
- Mon, 29 Jun 2026 21:12:34 GMT
86+
x-amzn-Remapped-Server:
87+
- nginx/1.30.3
88+
x-amzn-RequestId:
89+
- babb4d7a-b745-46f8-894d-fb2a070f8484
90+
status:
91+
code: 201
92+
message: Created
93+
version: 1

tests/resources/test_agents.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest
2+
3+
from cuenca.http.client import Session
4+
from cuenca.resources import Agent, AgentVerification
5+
6+
7+
@pytest.mark.vcr
8+
def test_agent_create():
9+
verification = AgentVerification.create() # Created by user in APP
10+
agent_session = Session()
11+
agent_session.configure(sandbox=True)
12+
agent = Agent.create(
13+
pairing_code=verification.pairing_code,
14+
phone_number=verification.phone_number,
15+
device_info={'client': 'cursor', 'os': 'macOS'},
16+
session=agent_session,
17+
)
18+
assert agent.id
19+
assert agent.agent_verification_id == verification.id
20+
assert agent.session_id
21+
assert agent.user_id
22+
assert agent.platform_id

0 commit comments

Comments
 (0)