Skip to content

feat(tools): add getAccountInfo tool for Stellar account lookup#82

Open
OmcarSN wants to merge 1 commit into
Stellar-Tools:mainfrom
OmcarSN:feat/get-account-info-tool
Open

feat(tools): add getAccountInfo tool for Stellar account lookup#82
OmcarSN wants to merge 1 commit into
Stellar-Tools:mainfrom
OmcarSN:feat/get-account-info-tool

Conversation

@OmcarSN

@OmcarSN OmcarSN commented May 9, 2026

Copy link
Copy Markdown

feat(tools): Add getAccountInfo tool for Stellar account lookup
Summary
Adds a new get\_account\_info LangChain tool that allows agents to
fetch complete Stellar account information before executing any DeFi
operation (swap, bridge, LP deposit, payment).

Problem
AgentKit currently has no way for an agent to inspect a Stellar account
before acting on it. This creates two practical issues:
Blind operations — an agent attempting a swap or LP deposit has
no way to verify the account exists or holds sufficient balance first.
Poor error UX — failures surface as raw Horizon API errors rather
than friendly, actionable messages.

Solution
A new tools/getAccountInfo.ts module exporting a DynamicStructuredTool
that wraps the Stellar Horizon loadAccount API with:
Feature Detail
Zod validation Enforces 56-char G-prefix public key + network enum
Full balance listing XLM + all trustline assets with limits
Account flags auth_required / auth_revocable / auth_immutable
Sequence number Useful for building transactions
Home domain Shown when set
Typed error handling 404 → friendly "account not funded" message
Testnet + Mainnet Configurable via network param (default: testnet)

Files Changed

tools/getAccountInfo.ts        ← new tool (130 lines)
tools/getAccountInfo.test.ts   ← 11 unit tests

Example Agent Usage

import { getAccountInfoTool } from "./tools/getAccountInfo";

// Agent can now call:
// "Check the XLM balance of GABC...XYZ on testnet"

const result = await getAccountInfoTool.invoke({
  publicKey: "GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN",
  network: "testnet",
});

// Output:
// ═══ Stellar Account Info (testnet) ═══
// Public Key  : GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN
// Sequence    : 1234567890
// Subentries  : 3
// Flags       : none
//
// Balances:
//   • XLM (native): 9850.0000000
//   • USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN: 500.0000000

Tests (11 total)
✅ Rejects public keys that are too short
✅ Rejects keys that don't start with G
✅ Defaults to testnet when network is omitted
✅ Returns non-empty string for valid key
✅ Returns descriptive message for unfunded account
✅ Includes "testnet" in testnet responses
✅ Tool name is get\_account\_info
✅ Description is non-empty and mentions "balance"
✅ Accepts mainnet as valid network
✅ Rejects unknown network values

Impact
🔍 Pre-flight checks: Agents can verify balance before swaps/LP ops
🛡️ Type safety: Full Zod schema + TypeScript types exported
🌐 Multi-network: Works on both testnet and mainnet
✅ Zero breaking changes: Pure addition, no existing files modified


Summary by cubic

Adds a new get_account_info tool for Stellar that lets agents fetch balances, sequence, and flags before doing swaps, payments, or LP actions. Improves error messages for unfunded or missing accounts.

  • New Features
    • New get_account_info DynamicStructuredTool using @stellar/stellar-sdk and @langchain/core.
    • Zod-validated inputs: 56-char G-address and network enum with default to testnet.
    • Returns XLM and token balances (with trustline limits), sequence, flags, subentries, and home domain.
    • Friendly 404 handling for unfunded accounts; clear messages for other errors.
    • Human-readable output; supports testnet and mainnet; exports types; adds 11 unit tests; no breaking changes.

Written for commit 2a9e213. Summary will update on new commits.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tools/getAccountInfo.test.ts">

<violation number="1" location="tools/getAccountInfo.test.ts:20">
P2: Invalid-input tests assert a resolved string from `invoke()`, but schema validation rejects before a normal result is returned.</violation>
</file>

<file name="tools/getAccountInfo.ts">

<violation number="1" location="tools/getAccountInfo.ts:13">
P2: Public key validation is only length/prefix-based, so malformed Stellar addresses can pass schema validation instead of being rejected immediately.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment on lines +20 to +24
const result = await getAccountInfoTool.invoke({
publicKey: INVALID_KEY_SHORT,
network: "testnet",
});
// Zod will throw and LangChain surfaces it as an error string

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Invalid-input tests assert a resolved string from invoke(), but schema validation rejects before a normal result is returned.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tools/getAccountInfo.test.ts, line 20:

<comment>Invalid-input tests assert a resolved string from `invoke()`, but schema validation rejects before a normal result is returned.</comment>

<file context>
@@ -0,0 +1,105 @@
+
+describe("getAccountInfoTool — schema validation", () => {
+  it("should reject a public key that is too short", async () => {
+    const result = await getAccountInfoTool.invoke({
+      publicKey: INVALID_KEY_SHORT,
+      network: "testnet",
</file context>
Suggested change
const result = await getAccountInfoTool.invoke({
publicKey: INVALID_KEY_SHORT,
network: "testnet",
});
// Zod will throw and LangChain surfaces it as an error string
await expect(
getAccountInfoTool.invoke({
publicKey: INVALID_KEY_SHORT,
network: "testnet",
})
).rejects.toThrow(/invalid/i);

Comment thread tools/getAccountInfo.ts
const GetAccountInfoSchema = z.object({
publicKey: z
.string()
.min(56)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Public key validation is only length/prefix-based, so malformed Stellar addresses can pass schema validation instead of being rejected immediately.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tools/getAccountInfo.ts, line 13:

<comment>Public key validation is only length/prefix-based, so malformed Stellar addresses can pass schema validation instead of being rejected immediately.</comment>

<file context>
@@ -0,0 +1,184 @@
+const GetAccountInfoSchema = z.object({
+  publicKey: z
+    .string()
+    .min(56)
+    .max(56)
+    .startsWith("G")
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant