AI Agents¶
Systems to learn:
Key Components¶
- Planning
- subgoal & decomposition
- reflection & refinement
- Memory: short term & long term
- Tool Use: external apis
Task Decomposition¶
Techniques: Chain-of-thought & Tree-of-thought
- by LLM with simple prompting like "Steps for XYZ.\n" or "What are the subgoals for achieving XYZ?"
- by using task-specific instructions; e.g. "Write a story outline." for writing a novel
- with human inputs.
Reflection¶
Techniques: ReAct, Reflexion, Chain-of-hindsight
Thought: ...
Action: ...
Observation: ...
... (Repeated many times)
Tool(api) usage¶
- Ability to call the API: given description, whether it can invoke api correctly
- Ability to retrieve the API: be able to find the appropriate api
- Ability to plan API calls: invoke multiple api calls to accomple a vague user request
Core¶
llm_agents' agent loop:
num_loops = 0
while num_loops < self.max_loops:
num_loops += 1
curr_prompt = prompt.format(previous_responses='\n'.join(previous_responses))
generated, tool, tool_input = self.decide_next_action(curr_prompt)
if tool == 'Final Answer':
return tool_input
if tool not in self.tool_by_names:
raise ValueError(f"Unknown tool: {tool}")
tool_result = self.tool_by_names[tool].use(tool_input)
generated += f"\n{OBSERVATION_TOKEN} {tool_result}\n{THOUGHT_TOKEN}"
previous_responses.append(generated)
- Construct prompt from previous actions & results
- Make a decision on which tools to use and input arguments
- Execute the tool with the arguments, and use the output as an observation
- Another call to LLM to do a thought