-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create agent, tool primitives and update example
- Loading branch information
Showing
6 changed files
with
84 additions
and
62 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Tool } from './tool.js' | ||
import { RequiredOptionals } from './types.js' | ||
|
||
export type AgentOptions = { | ||
role: string | ||
description: string | ||
tools?: { | ||
[key: string]: Tool | ||
} | ||
model?: string | ||
} | ||
|
||
const defaults: RequiredOptionals<AgentOptions> = { | ||
tools: {}, | ||
model: 'gpt-4o', | ||
} | ||
|
||
/** | ||
* Helper utility to create an agent with defaults. | ||
*/ | ||
export const agent = (options: AgentOptions) => { | ||
return { | ||
...defaults, | ||
...options, | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import z, { ZodTypeAny } from 'zod' | ||
|
||
export type Tool<P extends ZodTypeAny = any> = { | ||
description: string | ||
parameters: P | ||
execute: (parameters: z.infer<P>) => Promise<string> | ||
} | ||
|
||
export const tool = <P extends ZodTypeAny>(tool: Tool<P>): Tool<P> => tool |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Utility type to get optional keys from T. | ||
*/ | ||
export type OptionalKeys<T> = { | ||
[K in keyof T]-?: undefined extends T[K] ? K : never | ||
}[keyof T] | ||
|
||
/** | ||
* Utility type to get optional properties from T. | ||
*/ | ||
export type OptionalProperties<T> = Pick<T, OptionalKeys<T>> | ||
|
||
/** | ||
* Utility type to make optional properties required (only includes optional props). | ||
*/ | ||
export type RequiredOptionals<T> = Required<OptionalProperties<T>> |