feat(tools): add getAccountInfo tool for Stellar account lookup#82
Open
OmcarSN wants to merge 1 commit into
Open
feat(tools): add getAccountInfo tool for Stellar account lookup#82OmcarSN wants to merge 1 commit into
OmcarSN wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
| const GetAccountInfoSchema = z.object({ | ||
| publicKey: z | ||
| .string() | ||
| .min(56) |
There was a problem hiding this comment.
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(tools): Add
getAccountInfotool for Stellar account lookupSummary
Adds a new
get\_account\_infoLangChain tool that allows agents tofetch 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.tsmodule exporting aDynamicStructuredToolthat wraps the Stellar Horizon
loadAccountAPI 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
networkparam (default: testnet)Files Changed
Example Agent Usage
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_infotool 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.get_account_infoDynamicStructuredToolusing@stellar/stellar-sdkand@langchain/core.networkenum with default to testnet.Written for commit 2a9e213. Summary will update on new commits.