Replies: 1 comment
-
🤖 To add memory to your code, you can use the export class PromptGenerator {
// ...
memory: string[];
constructor() {
// ...
this.memory = [];
}
/**
* Adds a memory to the list of memories.
* @param memory The memory to add.
* @returns void
*/
add_memory(memory: string): void {
this.memory.push(memory);
}
/**
* Generates a memory string that includes the memories.
* @returns A string representing the memory.
*/
generate_memory_string(): string {
return this._generate_numbered_list(this.memory);
}
/**
* Generates a prompt string that includes the constraints, commands,
* resources, performance evaluations, memory, and response format.
* @returns A string representing the prompt.
*/
generate_prompt_string(): string {
// ...
const prompt_string =
`Constraints:\n${this._generate_numbered_list(this.constraints)}\n\n` +
`Commands:\n${this._generate_numbered_list(
this.commands,
"command"
)}\n\n` +
`Resources:\n${this._generate_numbered_list(this.resources)}\n\n` +
`Memory:\n${this.generate_memory_string()}\n\n` + // Add memory here
`Performance Evaluation:\n${this._generate_numbered_list(
this.performance_evaluation
)}\n\n` +
`You should only respond in JSON format as described below ` +
`\nResponse Format: \n${formatted_response_format} ` +
`\nEnsure the response can be parsed by Python json.loads`;
return prompt_string;
}
} You can then add memory to the export function getPrompt(tools: ObjectTool[]): string {
const prompt_generator = new PromptGenerator();
// ...
prompt_generator.add_memory(
"Previous task details and outcomes."
);
prompt_generator.add_memory(
"Important information saved from previous tasks."
);
const prompt_string = prompt_generator.generate_prompt_string();
return prompt_string;
} You can find more details about this in the langchain/src/experimental/autogpt/prompt_generator.ts and langchain/src/experimental/generative_agents/generative_agent_memory.ts files in the langchainjs repository. As for the I hope this helps! Let me know if you have any other questions. Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Given the code below, what would be the best way to add memory, or to apply a new code to include a prompt, memory, and keep the same functionality as this code:
Beta Was this translation helpful? Give feedback.
All reactions