Skip to content

Commit

Permalink
add structured planning agent (#13149)
Browse files Browse the repository at this point in the history
  • Loading branch information
logan-markewich committed Apr 30, 2024
1 parent c5a49e0 commit af8c8eb
Show file tree
Hide file tree
Showing 9 changed files with 1,625 additions and 7 deletions.
942 changes: 942 additions & 0 deletions docs/docs/examples/agent/structured_planner.ipynb

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/docs/module_guides/deploying/agents/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ For more detailed guides on how to use specific tools, check out our [tools modu
- [Multi Document Agents](../../../examples/agent/multi_document_agents.ipynb)
- [Agent Builder](../../../examples/agent/agent_builder.ipynb)
- [Parallel Function Calling](../../../examples/agent/openai_agent_parallel_function_calling.ipynb)
- [Agent with Planning](../../../examples/agent/structured_planner.ipynb)

## [Beta] OpenAI Assistant Agent

Expand Down Expand Up @@ -49,4 +50,5 @@ For more detailed guides on how to use specific tools, check out our [tools modu

- [Agent Runner](../../../examples/agent/agent_runner/agent_runner.ipynb)
- [Agent Runner RAG](../../../examples/agent/agent_runner/agent_runner_rag.ipynb)
- [Agent with Planning](../../../examples/agent/structured_planner.ipynb)
- [Controllable Agent Runner](../../../examples/agent/agent_runner/agent_runner_rag_controllable.ipynb)
21 changes: 21 additions & 0 deletions docs/docs/module_guides/deploying/agents/usage_pattern.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,27 @@ query_engine_tools = [
outer_agent = ReActAgent.from_tools(query_engine_tools, llm=llm, verbose=True)
```

## Agent With Planning

Breaking down an initial task into easier-to-digest sub-tasks is a powerful pattern.

LlamaIndex provides an agent planning module that does just this:

```python
from llama_index.agent.openai import OpenAIAgentWorker
from llama_index.core.agent import (
StructuredPlannerAgent,
FunctionCallingAgentWorker,
)

worker = FunctionCallingAgentWorker.from_tools(tools, llm=llm)
agent = StructuredPlannerAgent(worker)
```

In general, this agent may take longer to respond compared to the basic `AgentRunner` class, but the outputs will often be more complete. Another tradeoff to consider is that planning often requires a very capable LLM (for context, `gpt-3.5-turbo` is sometimes flakey for planning, while `gpt-4-turbo` does much better.)

See more in the [complete guide](../../../examples/agent/structured_planner.ipynb)

## Lower-Level API

The OpenAIAgent and ReActAgent are simple wrappers on top of an `AgentRunner` interacting with an `AgentWorker`.
Expand Down
1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ nav:
- ./examples/agent/coa_agent.ipynb
- ./examples/agent/lats_agent.ipynb
- ./examples/agent/llm_compiler.ipynb
- ./examples/agent/structured_planner.ipynb
- Callbacks:
- ./examples/callbacks/HoneyHiveLlamaIndexTracer.ipynb
- ./examples/callbacks/PromptLayerHandler.ipynb
Expand Down
2 changes: 2 additions & 0 deletions llama-index-core/llama_index/core/agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
from llama_index.core.agent.react.step import ReActAgentWorker
from llama_index.core.agent.react_multimodal.step import MultimodalReActAgentWorker
from llama_index.core.agent.runner.base import AgentRunner
from llama_index.core.agent.runner.planner import StructuredPlannerAgent
from llama_index.core.agent.runner.parallel import ParallelAgentRunner
from llama_index.core.agent.types import Task
from llama_index.core.chat_engine.types import AgentChatResponse
from llama_index.core.agent.function_calling.step import FunctionCallingAgentWorker

__all__ = [
"AgentRunner",
"StructuredPlannerAgent",
"ParallelAgentRunner",
"ReActAgentWorker",
"ReActAgent",
Expand Down

0 comments on commit af8c8eb

Please sign in to comment.