You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/*Pardon the mess this was put together in half a day for the [lablab.ai](https://lablab.ai/event/autonomous-gpt-agents-hackathon) hackathon.More updates to come# AC AGI An autonomous general intelligence that accomplishes a task for you.Uses human in the loop to provide feedback to the agent.How to use:- Enter your task- Wait for the agent to complete the task- Assign max-iterations for the agent to loop: 0 for infinite (probably not a good idea ¯\_(ツ)_/¯)- ProfitKnown issues:- The agent will sometimes get stuck in a loop and not complete the task- Human feedback is not always helpfulUpcoming features:- More tools- Refined prompts- Better human feedback system- Better memory systemPossible thanks to the fine folks at [Langchain](https://js.langchain.com/docs/use_cases/autonomous_agents/baby_agi#example-with-tools)and all the other giants whose shoulders we stand on.*/// Name: AC AGI// Description: An AGI task manager inspired by BabyAGI// Author: Josh Mabry// Twitter: @AI_Citizenimport"@johnlindquist/kit";let{ BabyAGI }=awaitimport("langchain/experimental/babyagi");let{ MemoryVectorStore }=awaitimport("langchain/vectorstores/memory");let{ OpenAIEmbeddings }=awaitimport("langchain/embeddings/openai");let{ OpenAI }=awaitimport("langchain/llms/openai");let{ PromptTemplate }=awaitimport("langchain/prompts");let{ LLMChain }=awaitimport("langchain/chains");let{ ChainTool }=awaitimport("langchain/tools");let{ initializeAgentExecutorWithOptions }=awaitimport("langchain/agents");let{ DynamicTool }=awaitimport("langchain/tools");let{ ChatOpenAI }=awaitimport("langchain/chat_models");letGOOGLE_API_KEY=awaitenv("GOOGLE_API_KEY",{shortcuts: [{name: "Google API Key",key: `${cmd}+o`,bar: "right",onPress: ()=>{open("https://developers.google.com/custom-search/v1/introduction");},},],ignoreBlur: true,secret: true,height: PROMPT.HEIGHT.INPUT_ONLY,});letGOOGLE_CSE_KEY=awaitenv("GOOGLE_CSE_KEY",{shortcuts: [{name: "Google Custom Search Engine Key",key: `${cmd}+o`,bar: "right",onPress: ()=>{open("https://programmablesearchengine.google.com/");},},],ignoreBlur: true,secret: true,height: PROMPT.HEIGHT.INPUT_ONLY,});awaitenv("OPENAI_API_KEY",{hint: `Grab a key from <a href="https://platform.openai.com/account/api-keys">here</a>`,});consttask=awaitarg({placeholder: "Task",description: "Enter a task for AC AGI to complete",ignoreBlur: true,height: PROMPT.HEIGHT.INPUT_ONLY,});letmaxIterations=awaitarg({placeholder: "How many times should AC AGI loop?",hint: "Leave empty for infinite iterations *use with caution*",ignoreBlur: true,height: PROMPT.HEIGHT.INPUT_ONLY,});if(maxIterations===""||maxIterations==="0"){maxIterations=undefined;}//#########################// BabyAGI method overrides//#########################functionprintTaskList(){letresult="";for(consttofthis.taskList){result+=`${t.taskID}: ${t.taskName}\n`;}constmsg=`### Task List${result} `;lethtml=md(msg);div({
html,ignoreBlur: true,});}functionprintNextTask(task){constmsg=`### Next Task${task.taskID}: ${task.taskName} `;lethtml=md(msg);div({
html,ignoreBlur: true,});}functionprintTaskResult(result){constmsg=`### Task Result${result.trim()} `;lethtml=md(msg);div({
html,ignoreBlur: true,});}//#############// Custom Tools//#############lethtml=(str)=>str.replace(//g,"+");letfetch=(q)=>`https://www.googleapis.com/customsearch/v1?key=${GOOGLE_API_KEY}&cx=${GOOGLE_CSE_KEY}&q=${html(q)}&sort=date`;asyncfunctionsearch(query){letresponse=awaitget(fetch(query));letitems=response?.data?.items;if(items){letchoices=items.map((item)=>({name: item.title,value: item.link,}));returnJSON.stringify(choices);}}asyncfunctionhumanFeedbackList(mdStr){lethtml=md(`${mdStr.trim()}`);constresponse=div({
html,ignoreBlur: true,});returnresponse;}asyncfunctionhumanInput(question){constresponse=awaitarg({placeholder: "Human, I need help!",hint: question,ignoreBlur: true,ignoreAbandon: true,height: PROMPT.HEIGHT.INPUT_ONLY,});returnresponse;}consttodoPrompt=PromptTemplate.fromTemplate("You are a planner/expert todo list creator. Generate a markdown formatted todo list for: {objective}");consttools=[newChainTool({name: "TODO",chain: newLLMChain({llm: newChatOpenAI({temperature: 0}),prompt: todoPrompt,}),description:
"For making todo lists. Input: objective to create todo list for. Output: the todo list",}),newDynamicTool({name: "Search",description: "Search web for info",func: search,}),newDynamicTool({name: "Human Input",description:
"(Use only when no info is available elsewhere) Ask a human for specific input that you don't know, like a persons name, or DOB, location, etc. Input is question to ask human, output is answer",func: humanInput,}),// new DynamicTool({// name: "Human Feedback Choice",// description: `Ask human for feedback if you unsure of next step.// Input is markdown string formatted with your questions and suitable responses like this example:// # Human, I need your help!// <Question Here>// * [John](submit:John) // don't change formatting of these links// * [Mindy](submit:Mindy)// * [Joy](submit:Joy)// * [Other](submit:Other)// `,// func: humanFeedbackList,// }),];//##################// AC AGI is Born//##################consttaskBeginMsg=md(`### Executing Task ManagerGoal: ${task}`);div({html: taskBeginMsg,ignoreBlur: true});constagentExecutor=awaitinitializeAgentExecutorWithOptions(tools,newChatOpenAI({temperature: 0}),{agentType: "zero-shot-react-description",agentArgs: {prefix: `You are an AI who performs one task based on the following objective: {objective}. Take into account these previously completed tasks: {context}.`,suffix: `Question: {task}{agent_scratchpad}`,inputVariables: ["objective","task","context","agent_scratchpad"],},});constvectorStore=newMemoryVectorStore(newOpenAIEmbeddings());constbabyAGI=BabyAGI.fromLLM({llm: newChatOpenAI({temperature: 0}),executionChain: agentExecutor,vectorstore: vectorStore,maxIterations: maxIterations,});babyAGI.printNextTask=printNextTask;babyAGI.printTaskList=printTaskList;babyAGI.printTaskResult=printTaskResult;awaitbabyAGI.call({objective: task});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Open ac-agi in Script Kit
Up to date script can be found in my Kenv here
Beta Was this translation helpful? Give feedback.
All reactions