///
This example demonstrates the foundational concepts of account management within the Quicksilver SDK, focusing on the creation of main agents, the delegation of sub-agents, and the management of accou
31 views
~31 views from guests
Guest views are estimated from total page views. These include anonymous visitors and users who weren't logged in when they viewed the page.
This example demonstrates the foundational concepts of account management within the Quicksilver SDK, focusing on the creation of main agents, the delegation of sub-agents, and the management of account properties such as limits and balances. It highlights the SDK's approach to using "active models" where accounts are not just static data but intelligent objects capable of performing actions.
For initial setup and client initialization, refer to the [Getting Started] guide.
The following TypeScript code illustrates how to create a main AI agent, delegate sub-agents to it, update limits, and retrieve account balances.
This line initializes the QuicksilverClient, pointing it to the sandbox environment. In a real application, you would provide your actual API key. The client acts as the central factory for all SDK interactions.
Here, we create a primary "AgentMain" account. This is a powerful feature where accounts are directly returned as active Account models. These models encapsulate both the account data and the methods to interact with it, adhering to the Active Record pattern. This simplifies operations, making your code more intuitive and type-safe.
The delegate() method is invoked directly on the mainAgent object. This demonstrates how accounts can establish hierarchical relationships, allowing a main agent to create and manage sub-agents with their own specific limits. This is crucial for building complex AI agent systems where different agents have different roles and spending capacities.
The getChildren() method allows you to fetch all accounts that have been delegated by mainAgent. This further emphasizes the active model's ability to expose relevant behaviors directly on the object.
Account limits can be dynamically updated using the updateLimits() method directly on the mainAgent instance. This method interacts with the API to persist the changes and then updates the mainAgent object with the latest data, ensuring the local model remains synchronized.
The getBalance() method fetches the current financial balance of the account. This demonstrates another direct action available on the Account active model.
This example showcases the Account active model and its core functionalities within the Quicksilver SDK. By allowing direct method calls on account objects for actions like delegate, getChildren, updateLimits, and getBalance, the SDK transforms traditional API interactions into a fluent, expressive, and type-safe domain-specific language. This approach streamlines development and reduces boilerplate code, moving towards the vision of programmable money with elegant design.
For a deeper dive into the Account model's methods and properties, please refer to the [API Reference: Account Model].
You can continue exploring other examples such as Fluent Transactions and Conditional Escrow to see how these active models integrate with other SDK features.