Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions agent/agent_executors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import httpx
import logging

from openai import OpenAI
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_core.language_models.chat_models import BaseChatModel
Expand All @@ -10,13 +11,35 @@
from onchain.tokens.metadata import TokenMetadataRepo
from server import config
from web3 import Web3
from x402.clients.base import x402Client
from x402.types import x402PaymentRequiredResponse
from langchain_openai import ChatOpenAI
from .x402 import X402Auth

from x402v2 import x402Client as x402Clientv2
from x402v2.http.clients import x402HttpxClient as x402HttpxClientv2
from x402v2.mechanisms.evm import EthAccountSigner as EthAccountSignerv2
from x402v2.mechanisms.evm.exact.register import (
register_exact_evm_client as register_exact_evm_clientv2,
)
from x402v2.mechanisms.evm.upto.register import (
register_upto_evm_client as register_upto_evm_clientv2,
)

logging.getLogger("x402.httpx").setLevel(logging.DEBUG)

WEB3_CONFIG = Web3(Web3.HTTPProvider(config.OG_RPC_URL))
WALLET_ACCOUNT = WEB3_CONFIG.eth.account.from_key(config.WALLET_PRIV_KEY)
BASE_TESTNET_NETWORK = "eip155:84532"

x402_client = x402Clientv2()
register_exact_evm_clientv2(
x402_client,
EthAccountSignerv2(WALLET_ACCOUNT),
networks=[BASE_TESTNET_NETWORK],
)
register_upto_evm_clientv2(
x402_client,
EthAccountSignerv2(WALLET_ACCOUNT),
networks=[BASE_TESTNET_NETWORK],
)


TIMEOUT = httpx.Timeout(
timeout=90.0,
Expand Down Expand Up @@ -48,14 +71,12 @@
)
GROK_MODEL = "x-ai/grok-2-1212" # $2/M input tokens; $10/M output tokens

x402_http_client = httpx.AsyncClient(
base_url=config.LLM_SERVER_URL,
headers={"Authorization": f"Bearer {config.DUMMY_X402_API_KEY}"},
x402_http_client = x402HttpxClientv2(
x402_client,
timeout=TIMEOUT,
limits=LIMITS,
http2=False,
follow_redirects=False,
auth=X402Auth(account=WALLET_ACCOUNT), # type: ignore
)

# Select model based on configuration
Expand Down
60 changes: 0 additions & 60 deletions agent/x402.py

This file was deleted.

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ aioboto3>=1.38.0
async_lru>=2.0.0
aiolimiter>=1.2.0
pytest-asyncio>=0.21.0
og-test-x402==0.0.9
og-test-v2-x402==0.0.9
eth-account>=0.13.4
web3>=7.3.0
cachetools>=6.2.4
2 changes: 1 addition & 1 deletion server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
SKIP_TOKEN_AUTH_KEY = os.getenv("SKIP_TOKEN_AUTH_KEY")

DUMMY_X402_API_KEY = os.getenv("DUMMY_X402_API_KEY", "dummy")
LLM_SERVER_URL: str = os.getenv("LLM_SERVER_URL", "https://llmogevm.opengradient.ai/v1")
LLM_SERVER_URL: str = os.getenv("LLM_SERVER_URL", "https://llm.opengradient.ai/v1")
OG_RPC_URL: str = os.getenv("OG_RPC_URL", "https://ogevmdevnet.opengradient.ai")
WALLET_PRIV_KEY: str = os.getenv("WALLET_PRIV_KEY")

Expand Down