diff --git a/examples/sentiment.ts b/examples/sentiment.ts
index b36e3cd..0c30539 100644
--- a/examples/sentiment.ts
+++ b/examples/sentiment.ts
@@ -13,12 +13,12 @@ export async function main() {
)
.input(z.object({ texts: z.string().array() }))
.output(z.array(z.object({ text: z.string(), label: z.string() })))
- .examples([
- { input: 'The food was digusting', output: 'negative' },
- { input: 'We had a fantastic night', output: 'positive' },
- { input: 'Recommended', output: 'positive' },
- { input: 'The waiter was rude', output: 'negative' }
- ])
+ // .examples([
+ // { input: 'The food was digusting', output: 'negative' },
+ // { input: 'We had a fantastic night', output: 'positive' },
+ // { input: 'Recommended', output: 'positive' },
+ // { input: 'The waiter was rude', output: 'negative' }
+ // ])
.call({
texts: [
'I went to this place and it was just so awful.',
diff --git a/readme.md b/readme.md
index 99406ef..33f316f 100644
--- a/readme.md
+++ b/readme.md
@@ -15,6 +15,7 @@
- [Development](#development)
- [Environment](#environment)
- [Local Testing](#local-testing)
+ - [Scratch](#scratch)
- [License](#license)
## Intro
@@ -55,6 +56,27 @@ Ensure you have `REDIS_URL_TEST` set to a valid redis connection URL.
pnpm test
```
+### Scratch
+
+- `@agentic/core`
+ - Task, Agentic, logging, caching, types, constants
+- `@agentic/human-feedback`
+- `@agentic/human-feedback-cli`
+- `@agentic/human-feedback-sms`
+- `@agentic/human-feedback-slack`
+- `@agentic/experimenation`
+- `@agentic/tools`
+- `@agentic/tools-serpapi`
+- `@agentic/tools-metaphor`
+- `@agentic/tools-browser`
+- `@agentic/tools-multion`
+- `@agentic/llms`
+- `@agentic/llms-openai`
+- `@agentic/llms-anthropic`
+- `@agentic/llms-huggingface`
+- `@agentic/agents`
+- `@agentic/cli`
+
## License
MIT © [Travis Fischer](https://transitivebullsh.it)
diff --git a/scratch/declarative-design-jsx-0.tsx b/scratch/declarative-design-jsx-0.tsx
index 9617680..e4ff702 100644
--- a/scratch/declarative-design-jsx-0.tsx
+++ b/scratch/declarative-design-jsx-0.tsx
@@ -30,6 +30,9 @@ async function ExampleLLMQuery({ texts }: { texts: string[] }) {
>
You are an expert sentiment-labelling assistant
+ {/* */}
+ {/* */}
+
Label the following texts as positive or negative:
{/* {texts.map((text) => `- ${text}\n`)} */}
diff --git a/src/llm.ts b/src/llm.ts
index 719757b..7893ea0 100644
--- a/src/llm.ts
+++ b/src/llm.ts
@@ -86,12 +86,6 @@ export abstract class BaseLLM<
this._modelParams = { ...this._modelParams, ...params } as TModelParams
return this
}
-
- // TODO
- // abstract stream({
- // input: TInput,
- // onProgress: types.ProgressFunction
- // }): Promise
}
export abstract class BaseChatModel<
@@ -117,9 +111,9 @@ export abstract class BaseChatModel<
messages: types.ChatMessage[]
): Promise>
- override async call(
+ protected override async _call(
input?: types.ParsedData
- ): Promise> {
+ ): Promise> {
if (this._inputSchema) {
const inputSchema =
this._inputSchema instanceof z.ZodType
@@ -248,9 +242,15 @@ export abstract class BaseChatModel<
// TODO: handle errors, retry logic, and self-healing
- return outputSchema.parse(output)
+ return {
+ result: outputSchema.parse(output),
+ metadata: {}
+ }
} else {
- return output
+ return {
+ result: output,
+ metadata: {}
+ }
}
}
}
diff --git a/src/task.ts b/src/task.ts
index 051291e..60655b5 100644
--- a/src/task.ts
+++ b/src/task.ts
@@ -6,8 +6,12 @@ import { Agentic } from './agentic'
/**
* A `Task` is a typed, async function call that may be non-deterministic.
*
+ * Invoking a task is equivalent to sampling from a probability distribution.
+ *
* Examples of tasks include:
* - LLM calls
+ * - Chain of LLM calls
+ * - Retrieval task
* - API calls
* - Native function calls
* - Invoking sub-agents
@@ -17,8 +21,9 @@ export abstract class BaseTask<
TOutput extends ZodRawShape | ZodTypeAny = ZodTypeAny
> {
protected _agentic: Agentic
- protected _timeoutMs: number | undefined
- protected _retryConfig: types.RetryConfig | undefined
+
+ protected _timeoutMs?: number
+ protected _retryConfig?: types.RetryConfig
constructor(options: types.BaseTaskOptions) {
this._agentic = options.agentic
@@ -45,9 +50,21 @@ export abstract class BaseTask<
return this
}
- public abstract call(
+ public async call(
input?: types.ParsedData
- ): Promise>
+ ): Promise> {
+ return this._call(input).then((response) => response.result)
+ }
+
+ public async callWithMetadata(
+ input?: types.ParsedData
+ ): Promise> {
+ return this._call(input)
+ }
+
+ protected abstract _call(
+ input?: types.ParsedData
+ ): Promise>
// TODO
// abstract stream({
diff --git a/src/tools/metaphor.ts b/src/tools/metaphor.ts
index 7f92bf0..0680ab5 100644
--- a/src/tools/metaphor.ts
+++ b/src/tools/metaphor.ts
@@ -1,5 +1,6 @@
import { z } from 'zod'
+import * as types from '../types'
import { Agentic } from '../agentic'
import { MetaphorClient } from '../services/metaphor'
import { BaseTask } from '../task'
@@ -57,15 +58,20 @@ export class MetaphorSearchTool extends BaseTask<
return MetaphorSearchToolOutputSchema
}
- override async call(
+ protected override async _call(
input: MetaphorSearchToolInput
- ): Promise {
+ ): Promise> {
// TODO: handle errors gracefully
input = this.inputSchema.parse(input)
- return this._metaphorClient.search({
+ const result = await this._metaphorClient.search({
query: input.query,
numResults: input.numResults
})
+
+ return {
+ result,
+ metadata: {}
+ }
}
}
diff --git a/src/types.ts b/src/types.ts
index ecd6a46..310cfb1 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -105,4 +105,12 @@ export interface RetryConfig {
strategy: string
}
+export interface TaskResponse<
+ TOutput extends ZodRawShape | ZodTypeAny = z.ZodType,
+ TMetadata extends Record = Record
+> {
+ result: ParsedData
+ metadata: TMetadata
+}
+
// export type ProgressFunction = (partialResponse: ChatMessage) => void