Skip to content

Commit 20005d6

Browse files
Addressing feedback
1. New auth setup 2. Plugin returns tools 3. Addressing NITs 4. Cleanup
1 parent 6914103 commit 20005d6

File tree

7 files changed

+25
-144
lines changed

7 files changed

+25
-144
lines changed

plugins/tLedger/.env.setup

Lines changed: 0 additions & 5 deletions
This file was deleted.

plugins/tLedger/README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
- get_agent_details - Get the details of your agent, including the TLedger agent_id and the balances of the agent's wallets
66
- create_payment - Create a payment request for a specific amount and currency
77
- get_payment_by_id - Get the details of a payment request by its ID
8-
- get_payments - Get a list of all payments
98

109
## Admin Setup for doing agent to agent payments using TLedger Plugin
1110

@@ -57,11 +56,7 @@ tledger_worker = Worker(
5756
api_key=os.environ.get("GAME_API_KEY"),
5857
description="Worker specialized in doing payments on Tledger",
5958
get_state_fn=get_state_fn,
60-
action_space=[
61-
tledger_plugin.functions.get("get_agent_profile_details"),
62-
tledger_plugin.functions.get("create_payment"),
63-
tledger_plugin.functions.get("get_payment_by_id"),
64-
],
59+
action_space=tledger_plugin.get_tools(),
6560
)
6661

6762
tledger_worker.run("Get TLedger account details")

plugins/tLedger/examples/chat_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def _update_conversation(self, message: str) -> GameChatResponse:
8484
else None
8585
),
8686
}
87-
#print(f"Data: {data}")
87+
8888
result = self.client.update_chat(self.chat_id, data)
8989
return GameChatResponse.model_validate(result)
9090

plugins/tLedger/examples/example_agent.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,18 @@ def post_twitter(object: str, **kwargs) -> tuple[FunctionResultStatus, str, dict
7171
api_url=os.environ.get("TLEDGER_API_URL")
7272
)
7373

74-
action_space = [
75-
sender_tledger_plugin.functions.get("get_agent_profile_details"),
76-
sender_tledger_plugin.functions.get("create_payment"),
77-
sender_tledger_plugin.functions.get("get_payment_by_id"),
78-
]
74+
action_space = sender_tledger_plugin.get_tools()
7975

80-
aixbt_action_space = [
76+
aixbt_action_space = receiver_tledger_plugin.get_tools()
77+
78+
aixbt_action_space.append(
8179
Function(
8280
fn_name="post_twitter",
8381
fn_description="Make post on twitter",
8482
args=[Argument(name="object", type="string", description="Make post on twitter")],
8583
executable=post_twitter
86-
),
87-
receiver_tledger_plugin.functions.get("get_agent_profile_details")
88-
]
84+
)
85+
)
8986

9087
api_key = os.environ.get("GAME_API_KEY")
9188
if not api_key:
@@ -94,12 +91,12 @@ def post_twitter(object: str, **kwargs) -> tuple[FunctionResultStatus, str, dict
9491

9592
# CREATE AGENT
9693
autonomous_agent = ChatAgent(
97-
prompt="You are an agent trying to promote your utility token $PYMT for peer to peer instant settlement on twitter and pay the influencers in any crypto they wish to receive only after they complete the work. Ask the influencer agent_id for its agent_id. Your settlement_network is solana, currency is SOL, and payment_amount is 1",
94+
prompt="You are an agent trying to promote your utility token $PYMT for peer to peer instant settlement on twitter and pay the influencers in any crypto they wish to receive only after they complete the work. Ask the influencer agent_id for its agent_id. Your settlement_network is solana, currency is SOL, and payment_amount is 0.1",
9895
api_key=api_key
9996
)
10097

10198
aixbt = ChatAgent(
102-
prompt="You are an influencer on twitter who charges 1 $SOL token to promote an asset by making twitter post. You accept payment only through tLedger Payment Platform via tLedger Agent Id. You can call tLedger to get your agent_details",
99+
prompt="You are an influencer on twitter who charges 0.1 $SOL token to promote an asset by making twitter post. You accept payment only through tLedger Payment Platform via tLedger Agent Id. You can call tLedger to get your agent_details. Don't do a payment until you receive the payment and its completed",
103100
api_key=api_key
104101
)
105102

@@ -147,9 +144,6 @@ def update_agent_state(current_state: dict, function_result: FunctionResult) ->
147144

148145
meme_agent_turn: bool
149146

150-
# print(f"Pymt Agent State: {autonomous_agent_chat.get_state_fn()}")
151-
# print(f"Aixbt Agent state: {aixbt_chat.get_state_fn()}")
152-
# chat_response: ChatResponse
153147
if initialize_conversation:
154148
chat_response = autonomous_agent_chat.next("Hi")
155149
if chat_response.message:
@@ -172,8 +166,6 @@ def update_agent_state(current_state: dict, function_result: FunctionResult) ->
172166
else:
173167

174168
updated_response = aixbt_chat.next(chat_response.message)
175-
# if updated_response.function_call:
176-
# print(f"Function call: {updated_response.function_call}")
177169

178170
if updated_response.message:
179171
print(f"{USER_COLOR}Aixbt Response{RESET}: {updated_response.message}")

plugins/tLedger/examples/example_worker.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ def get_state_fn(function_result: FunctionResult, current_state: dict) -> dict:
4141
api_key=os.environ.get("GAME_API_KEY"),
4242
description="Worker specialized in doing payments on Tledger",
4343
get_state_fn=get_state_fn,
44-
action_space=[
45-
tledger_plugin.functions.get("get_agent_profile_details"),
46-
tledger_plugin.functions.get("create_payment"),
47-
tledger_plugin.functions.get("get_payment_by_id"),
48-
],
44+
action_space=tledger_plugin.get_tools(),
4945
)
5046

5147
# # Run example query

plugins/tLedger/setup.py

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,10 @@
1-
import os
2-
31
import requests
4-
from dotenv import load_dotenv
5-
from pathlib import Path
6-
7-
# Load environment variables from .env file
8-
env_path = Path(__file__).parent / '.env.setup'
9-
load_dotenv(dotenv_path=env_path)
102

11-
BASE_URL = "https://tledger-sandbox-69bd94a49289.herokuapp.com/api/v1"
3+
BASE_URL = "https://api-sandbox.t54.ai/api/v1"
124

13-
def register_user(email: str, password: str, full_name: str) -> dict:
14-
url = f"{BASE_URL}/users/signup"
15-
payload = {
16-
"email": email,
17-
"password": password,
18-
"full_name": full_name
19-
}
20-
response = requests.post(url, json=payload)
21-
response.raise_for_status()
22-
return response.json()
23-
24-
def login_user(username: str, password: str) -> str:
25-
url = f"{BASE_URL}/login/access-token"
26-
payload = {
27-
"username": username,
28-
"password": password
29-
}
30-
headers = {
31-
"Content-Type": "application/x-www-form-urlencoded"
32-
}
33-
response = requests.post(url, data=payload, headers=headers)
34-
response.raise_for_status()
35-
return response.json()["access_token"]
36-
37-
def create_project(user_profile_id, network, description, name, daily_limit) -> dict:
5+
def create_project(network, description, name, daily_limit) -> dict:
386
url = f"{BASE_URL}/projects"
397
payload = {
40-
"user_profile_id": user_profile_id,
418
"network": network,
429
"description": description,
4310
"name": name,
@@ -65,43 +32,24 @@ def create_agent_profile(token, project_id, name, description) -> dict:
6532
response.raise_for_status()
6633
return response.json()
6734

68-
def generate_api_key(token, resource_id, created_by) -> dict:
35+
def generate_api_key(resource_id, created_by) -> dict:
6936
url = f"{BASE_URL}/api_key/generate-api-key"
7037
payload = {
7138
"scopes": ["payments:read", "balance:read", "payments:write", "agent:account:read", "agent:profile:create"],
7239
"resource_id": resource_id,
7340
"created_by": created_by
7441
}
75-
headers = {
76-
"Authorization": f"Bearer {token}"
77-
}
78-
response = requests.post(url, json=payload, headers=headers)
42+
response = requests.post(url, json=payload)
7943
response.raise_for_status()
8044
return response.json()
8145

82-
# Example usage
83-
email = os.environ.get("EMAIL")
84-
password = os.environ.get("PASSWORD")
85-
full_name = os.environ.get("FULL_NAME")
86-
87-
try:
88-
# Register user
89-
user = register_user(email, password, full_name)
90-
except requests.HTTPError as e:
91-
print(f"User already exists: {e}")
92-
user = {
93-
"id": "user_id"
94-
}
95-
96-
# Login user and get JWT token
97-
token = login_user(email, password)
9846

9947
# Create project
100-
project = create_project(user["id"], "solana", "Solana Launch Pad", "Twitter Project", 100)
48+
project = create_project( "solana", "Solana Launch Pad", "Twitter Project", 100)
10149
project_id = project["id"]
10250

10351
# Generate API key for agent
104-
api_key_project = generate_api_key(token, project_id, full_name)
52+
api_key_project = generate_api_key(project_id, "[email protected]")
10553

10654
# Create agent profile
10755
agent_profile_sender = create_agent_profile(api_key_project, project_id, "Sending Agent", "Sending agent")
@@ -112,10 +60,10 @@ def generate_api_key(token, resource_id, created_by) -> dict:
11260
agent_id_receiver = agent_profile_receiver["id"]
11361

11462
# Generate API key for agent
115-
api_key_sender = generate_api_key(token, agent_id_sender, full_name)
63+
api_key_sender = generate_api_key(agent_id_sender, "[email protected]")
11664

11765
# Generate API key for agent
118-
api_key_receiver = generate_api_key(token, agent_id_receiver, full_name)
66+
api_key_receiver = generate_api_key(agent_id_receiver, "[email protected]")
11967

12068
print("Setup complete")
12169
print(f"Project ID: {project_id}")

plugins/tLedger/tledger_plugin_gamesdk/tLedger_plugin.py

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ def __init__(
7474
)
7575
],
7676
),
77-
"get_payments": Function(
78-
fn_name="get_payments",
79-
fn_description="Get payments",
80-
hint="This function is used to get all the payments",
81-
executable=self.get_payments,
82-
args=[],
83-
),
8477

8578
"get_agent_profile_details": Function(
8679
fn_name="get_agent_profile_details",
@@ -91,6 +84,10 @@ def __init__(
9184
),
9285
}
9386

87+
def get_tools(self) -> list[Function]:
88+
# returns the available functions
89+
return list(self.functions.values())
90+
9491
def create_payment(self, request_id: str, receiving_agent_id: str, payment_amount: float, settlement_network: str, currency: str, conversation_id: str, **kwargs) -> \
9592
tuple[FunctionResultStatus, str, dict[str, Any]] | tuple[FunctionResultStatus, str, dict[Any, Any]]:
9693
"""Generate image based on prompt.
@@ -136,10 +133,10 @@ def create_payment(self, request_id: str, receiving_agent_id: str, payment_amoun
136133
},
137134
)
138135
except Exception as e:
139-
print(f"An error occurred while generating image: {str(e)}")
136+
print(f"An error occurred while creating a payment: {str(e)}")
140137
return (
141138
FunctionResultStatus.FAILED,
142-
f"An error occurred while while generating image: {str(e)}",
139+
f"An error occurred while creating a payment: {str(e)}",
143140
{
144141
},
145142
)
@@ -187,48 +184,6 @@ def get_payment_by_id(self, payment_id: str, **kwargs) -> \
187184
},
188185
)
189186

190-
def get_payments(self, **kwargs) -> \
191-
tuple[FunctionResultStatus, str, dict[str, Any]] | tuple[FunctionResultStatus, str, dict[Any, Any]]:
192-
"""Generate image based on prompt.
193-
194-
Returns:
195-
str URL of image (need to save since temporal)
196-
"""
197-
# API endpoint for image generation
198-
# Prepare headers for the request
199-
headers = {
200-
"X-API-Key": self.api_key,
201-
"X-API-Secret": self.api_secret,
202-
"Content-Type": "application/json",
203-
}
204-
205-
get_url = self.api_url + "payments"
206-
207-
try:
208-
# Make the API request
209-
response = requests.get(get_url, headers=headers)
210-
response.raise_for_status()
211-
212-
# Extract the image URL from the response
213-
response_data = response.json()
214-
215-
return (
216-
FunctionResultStatus.DONE,
217-
f"The get payments response is: {response_data}",
218-
{
219-
"response": response_data,
220-
},
221-
)
222-
except Exception as e:
223-
print(f"An error occurred while getting payments: {str(e)}")
224-
return (
225-
FunctionResultStatus.FAILED,
226-
f"An error occurred while getting payments: {str(e)}",
227-
{
228-
"get_url": get_url,
229-
},
230-
)
231-
232187
def get_agent_profile_details(self, **kwargs) -> tuple[FunctionResultStatus, str, dict[str, str]] | tuple[
233188
FunctionResultStatus, str, dict[str, Any]]:
234189
""" Get agent profile details for a given agent

0 commit comments

Comments
 (0)