-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9f3ef9
commit 8f0a25b
Showing
5 changed files
with
87 additions
and
245 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
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 |
---|---|---|
@@ -1,61 +1,15 @@ | ||
import OpenAI from 'openai'; | ||
import { | ||
ChatCompletionCreateParamsNonStreaming, | ||
ChatCompletionCreateParamsStreaming, | ||
} from 'openai/resources'; | ||
import { | ||
AnyEventObject, | ||
ObservableActorLogic, | ||
PromiseActorLogic, | ||
} from 'xstate'; | ||
import { AnyStateMachine } from 'xstate'; | ||
import { ObservedState } from './agent'; | ||
import { ZodEventMapping } from './schemas'; | ||
import { AgentPlan } from './utils'; | ||
|
||
export interface StatelyAgentAdapter { | ||
model: string; | ||
/** | ||
* Creates actor logic that chooses an event from all of the | ||
* possible next events of the parent state machine | ||
* and sends it to the parent actor. | ||
*/ | ||
fromEvent: <TInput>( | ||
inputFn: (input: TInput) => string | ChatCompletionCreateParamsNonStreaming | ||
) => PromiseActorLogic<AnyEventObject[] | undefined, TInput>; | ||
/** | ||
* Creates actor logic that resolves with a chat completion. | ||
*/ | ||
fromChat: <TInput>( | ||
inputFn: (input: TInput) => string | ChatCompletionCreateParamsNonStreaming | ||
) => PromiseActorLogic<OpenAI.Chat.Completions.ChatCompletion, TInput>; | ||
/** | ||
* Creates actor logic that emits a chat completion stream. | ||
*/ | ||
fromChatStream: <TInput>( | ||
inputFn: (input: TInput) => string | ChatCompletionCreateParamsStreaming | ||
) => ObservableActorLogic< | ||
OpenAI.Chat.Completions.ChatCompletionChunk, | ||
TInput | ||
>; | ||
/** | ||
* Creates actor logic that chooses a tool from the provided | ||
* tools and runs that tool. | ||
*/ | ||
fromTool: <TInput>( | ||
inputFn: (input: TInput) => string | ChatCompletionCreateParamsNonStreaming, | ||
tools: { | ||
[key: string]: Tool<any, any>; | ||
} | ||
) => PromiseActorLogic< | ||
| { | ||
result: any; | ||
tool: string; | ||
toolCall: OpenAI.Chat.Completions.ChatCompletionMessageToolCall; | ||
} | ||
| undefined, | ||
TInput | ||
>; | ||
export interface Planner { | ||
plan: (stuff: { | ||
goal: string; | ||
state: ObservedState; | ||
events: ZodEventMapping; | ||
logic: AnyStateMachine; | ||
}) => Promise<AgentPlan | undefined>; | ||
} | ||
|
||
export interface Tool<TInput, TOutput> { | ||
description: string; | ||
inputSchema: any; | ||
run: (input: TInput) => TOutput; | ||
} | ||
// A planner returns a plan for how to achieve a goal. |
Oops, something went wrong.