-
Notifications
You must be signed in to change notification settings - Fork 167
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
3ce5af6
commit c0cc30b
Showing
12 changed files
with
186 additions
and
57 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
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
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,65 @@ | ||
import { | ||
LLMParameters, | ||
Tool, | ||
InputSchema, | ||
ExecutionContext, | ||
DocumentAgentToolInput, | ||
DocumentAgentToolOutput, | ||
Message, | ||
} from '@/types'; | ||
|
||
export class DocumentAgentTool implements Tool<DocumentAgentToolInput, DocumentAgentToolOutput> { | ||
name: string; | ||
description: string; | ||
input_schema: InputSchema; | ||
|
||
constructor() { | ||
this.name = 'document_agent'; | ||
this.description = 'A document agent that can help you write document or long text, e.g. research report, email draft, summary.'; | ||
this.input_schema = { | ||
"type": "object", | ||
"properties": { | ||
"type": { | ||
"type": "string", | ||
"description": "The type of document to be created (e.g., 'report', 'presentation', 'article')." | ||
}, | ||
"title": { | ||
"type": "string", | ||
"description": "The title of the document." | ||
}, | ||
"background": { | ||
"type": "string", | ||
"description": "The background information or target for the document." | ||
}, | ||
"keypoints": { | ||
"type": "string", | ||
"description": "A summary of the key points or main ideas to be included in the document." | ||
}, | ||
"style": { | ||
"type": "string", | ||
"description": "The desired style or tone of the document (e.g., 'formal', 'casual', 'academic')." | ||
}, | ||
}, | ||
"required": ["type", "title", "background", "keypoints"], | ||
}; | ||
} | ||
|
||
async execute(context: ExecutionContext, params: DocumentAgentToolInput): Promise<DocumentAgentToolOutput> { | ||
params.references = context.variables; | ||
const messages: Message[] = [ | ||
{ | ||
role: 'system', | ||
content: 'You are an excellent writer, skilled at composing various types of copywriting and texts in different styles. You can draft documents based on the title, background, or reference materials provided by clients. Now, the client will provide you with a lot of information, including the type of copywriting, title, background, key points, style, and reference materials. Please write a document in Markdown format.', | ||
}, | ||
{ | ||
role: 'user', | ||
content: JSON.stringify(params), | ||
}, | ||
]; | ||
const llmParams: LLMParameters = { maxTokens: 8192 }; | ||
const response = await context.llmProvider.generateText(messages, llmParams); | ||
const content = typeof response.content == 'string' ? response.content : (response.content as any[])[0].text; | ||
context.variables.set("workflow_transcript", content); | ||
return { status: "OK", content }; | ||
} | ||
} |
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,35 @@ | ||
import { Tool, InputSchema, ExecutionContext } from "@/types"; | ||
|
||
export class WriteContextTool implements Tool<any, any> { | ||
name = 'write_context'; | ||
description = | ||
'Write a value to the global workflow context. Use this to store important intermediate results, but only when a piece of information is essential for future reference but missing from the final output specification of the current action.'; | ||
input_schema = { | ||
type: 'object', | ||
properties: { | ||
key: { | ||
type: 'string', | ||
description: 'The key to store the value under', | ||
}, | ||
value: { | ||
type: 'string', | ||
description: 'The value to store (must be JSON stringified if object/array)', | ||
}, | ||
}, | ||
required: ['key', 'value'], | ||
} as InputSchema; | ||
|
||
async execute(context: ExecutionContext, params: unknown): Promise<unknown> { | ||
const { key, value } = params as { key: string; value: string }; | ||
try { | ||
// Try to parse the value as JSON | ||
const parsedValue = JSON.parse(value); | ||
context.variables.set(key, parsedValue); | ||
} catch { | ||
// If parsing fails, store as string | ||
context.variables.set(key, value); | ||
} | ||
return { success: true, key, value }; | ||
} | ||
} | ||
|