Skip to content

Commit

Permalink
chore: langchain helper to convert actions to tools
Browse files Browse the repository at this point in the history
  • Loading branch information
John-peterson-coinbase committed Jan 30, 2025
1 parent 2893ec8 commit 9939a11
Show file tree
Hide file tree
Showing 14 changed files with 949 additions and 537 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export abstract class ActionProvider<TWalletProvider extends WalletProvider = Wa
* @param name - The name of the action provider.
* @param actionProviders - The action providers to combine.
*/
constructor(name: string, actionProviders: ActionProvider<TWalletProvider>[]) {
constructor(
name: string,
// Update parameter type to match property type
actionProviders: ActionProvider<TWalletProvider>[],
) {
this.name = name;
this.actionProviders = actionProviders;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ export class CdpActionProvider extends ActionProvider {
constructor(config: CdpActionProviderConfig = {}) {
if (config.apiKeyName && config.apiKeyPrivateKey) {
Coinbase.configure({ apiKeyName: config.apiKeyName, privateKey: config.apiKeyPrivateKey });
} else {
Coinbase.configureFromJson();
}

Coinbase.configureFromJson();

super("cdp", []);
}

Expand Down Expand Up @@ -112,4 +112,5 @@ from another wallet and provide the user with your wallet details.`,
supportsNetwork = (_: Network) => true;
}

export const cdpActionProvider = () => new CdpActionProvider();
export const cdpActionProvider = (config: CdpActionProviderConfig = {}) =>
new CdpActionProvider(config);
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,5 @@ A failure response will return a message with the Farcaster API request error:
supportsNetwork = (_: Network) => true;
}

export const farcasterActionProvider = () => new FarcasterActionProvider();
export const farcasterActionProvider = (config: FarcasterActionProviderConfig = {}) =>
new FarcasterActionProvider(config);
5 changes: 5 additions & 0 deletions cdp-agentkit-core/typescript/src/action_providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ export * from "./action_decorator";
export * from "./action_provider";

export * from "./pyth";
export * from "./cdp";
export * from "./erc721";
export * from "./morpho";
export * from "./basename";
export * from "./farcaster";
19 changes: 15 additions & 4 deletions cdp-agentkit-core/typescript/src/agentkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface AgentKitOptions {
export class AgentKit {
private walletProvider: WalletProvider;
private actionProviders?: ActionProvider[];
private actions: Action[];
private actions?: Action[];

/**
* Initializes a new AgentKit instance
Expand All @@ -28,15 +28,26 @@ export class AgentKit {
*/
public constructor(config: AgentKitOptions = {}) {
this.walletProvider = config.walletProvider || new CdpWalletProvider();
this.actionProviders = config.actionProviders;
this.actionProviders = config.actionProviders || [];
this.actions = config.actions || [];
}

/**
* Returns the actions available to the AgentKit.
*
* @returns An array of actions
*/
public getActions(): Action[] {
// TODO: Implement
throw Error("Unimplemented");
let actions: Action[] = this.actions || [];

if (this.actionProviders) {
for (const actionProvider of this.actionProviders) {
if (actionProvider.supportsNetwork(this.walletProvider.getNetwork())) {
actions = actions.concat(actionProvider.getActions(this.walletProvider));
}
}
}

return actions;
}
}
Loading

0 comments on commit 9939a11

Please sign in to comment.