Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build_documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- 'docs/source/**'
- 'assets/**'
- '.github/workflows/doc-build.yml'
- 'pyproject.toml'

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/en/examples/multiagents.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ manager_agent = CodeAgent(
That's all! Now let's run our system! We select a question that requires both some calculation and research:

```py
answer = manager_agent.run("If LLM trainings continue to scale up at the current rhythm until 2030, what would be the electric power in GW required to power the biggest training runs by 2030? What does that correspond to, compared to some contries? Please provide a source for any number used.")
answer = manager_agent.run("If LLM training continues to scale up at the current rhythm until 2030, what would be the electric power in GW required to power the biggest training runs by 2030? What would that correspond to, compared to some countries? Please provide a source for any numbers used.")
```

We get this report as the answer:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/en/examples/rag.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This agent will: ✅ Formulate the query itself and ✅ Critique to re-retrieve

So it should naively recover some advanced RAG techniques!
- Instead of directly using the user query as the reference in semantic search, the agent formulates itself a reference sentence that can be closer to the targeted documents, as in [HyDE](https://huggingface.co/papers/2212.10496).
The agent can the generated snippets and re-retrieve if needed, as in [Self-Query](https://docs.llamaindex.ai/en/stable/examples/evaluation/RetryQuery/).
The agent can use the generated snippets and re-retrieve if needed, as in [Self-Query](https://docs.llamaindex.ai/en/stable/examples/evaluation/RetryQuery/).

Let's build this system. 🛠️

Expand Down
4 changes: 2 additions & 2 deletions docs/source/en/tutorials/building_good_agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ Here are the rules you should always follow to solve your task:
Now Begin! If you solve the task correctly, you will receive a reward of $1,000,000.
```

As yo can see, there are placeholders like `"{{tool_descriptions}}"`: these will be used upon agent initialization to insert certain automatically generated descriptions of tools or managed agents.
As you can see, there are placeholders like `"{{tool_descriptions}}"`: these will be used upon agent initialization to insert certain automatically generated descriptions of tools or managed agents.

So while you can overwrite this system prompt template by passing your custom prompt as an argument to the `system_prompt` parameter, your new system promptmust contain the following placeholders:
So while you can overwrite this system prompt template by passing your custom prompt as an argument to the `system_prompt` parameter, your new system prompt must contain the following placeholders:
- `"{{tool_descriptions}}"` to insert tool descriptions.
- `"{{managed_agents_description}}"` to insert the description for managed agents if there are any.
- For `CodeAgent` only: `"{{authorized_imports}}"` to insert the list of authorized imports.
Expand Down
4 changes: 2 additions & 2 deletions docs/source/en/tutorials/secure_code_execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ This interpreter is designed for security by:
- Capping the number of operations to prevent infinite loops and resource bloating.
- Will not perform any operation that's not pre-defined.

Wev'e used this on many use cases, without ever observing any damage to the environment.
We've used this on many use cases, without ever observing any damage to the environment.

However this solution is not watertight: one could imagine occasions where LLMs fine-tuned for malignant actions could still hurt your environment. For instance if you've allowed an innocuous package like `Pillow` to process images, the LLM could generate thousands of saves of images to bloat your hard drive.
It's certainly not likely if you've chosen the LLM engine yourself, but it could happen.
Expand Down Expand Up @@ -79,4 +79,4 @@ agent = CodeAgent(
agent.run("What was Abraham Lincoln's preferred pet?")
```

E2B code execution is not compatible with multi-agents at the moment - because having an agent call in a code blob that should be executed remotely is a mess. But we're working on adding it!
E2B code execution is not compatible with multi-agents at the moment - because having an agent call in a code blob that should be executed remotely is a mess. But we're working on adding it!
8 changes: 4 additions & 4 deletions docs/source/en/tutorials/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ model_downloads_tool.push_to_hub("{your_username}/hf-model-downloads", token="<Y
```

For the push to Hub to work, your tool will need to respect some rules:
- All method are self-contained, e.g. use variables that come either from their args.
- As per the above point, **all imports should be defined directky within the tool's functions**, else you will get an error when trying to call [`~Tool.save`] or [`~Tool.push_to_hub`] with your custom tool.
- All methods are self-contained, e.g. use variables that come either from their args.
- As per the above point, **all imports should be defined directly within the tool's functions**, else you will get an error when trying to call [`~Tool.save`] or [`~Tool.push_to_hub`] with your custom tool.
- If you subclass the `__init__` method, you can give it no other argument than `self`. This is because arguments set during a specific tool instance's initialization are hard to track, which prevents from sharing them properly to the hub. And anyway, the idea of making a specific class is that you can already set class attributes for anything you need to hard-code (just set `your_variable=(...)` directly under the `class YourTool(Tool):` line). And of course you can still create a class attribute anywhere in your code by assigning stuff to `self.your_variable`.


Expand Down Expand Up @@ -210,7 +210,7 @@ Just make sure the new tool follows the same API as the replaced tool or adapt t
### Use a collection of tools

You can leverage tool collections by using the ToolCollection object, with the slug of the collection you want to use.
Then pass them as a list to initialize you agent, and start using them!
Then pass them as a list to initialize your agent, and start using them!

```py
from smolagents import ToolCollection, CodeAgent
Expand All @@ -224,4 +224,4 @@ agent = CodeAgent(tools=[*image_tool_collection.tools], model=model, add_base_to
agent.run("Please draw me a picture of rivers and lakes.")
```

To speed up the start, tools are loaded only if called by the agent.
To speed up the start, tools are loaded only if called by the agent.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "smolagents"
version = "1.1.0.dev0"
version = "1.2.0.dev0"
description = "🤗 smolagents: a barebones library for agents. Agents write python code to call tools or orchestrate other agents."
authors = [
{ name="Aymeric Roucher", email="[email protected]" }, { name="Thomas Wolf"},
Expand Down
2 changes: 1 addition & 1 deletion src/smolagents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__version__ = "1.1.0.dev0"
__version__ = "1.2.0.dev0"

from typing import TYPE_CHECKING

Expand Down
5 changes: 2 additions & 3 deletions src/smolagents/default_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,11 @@ def forward(self, question):

class DuckDuckGoSearchTool(Tool):
name = "web_search"
description = """Performs a duckduckgo web search based on your query (think a Google search) then returns the top search results as a list of dict elements.
Each result has keys 'title', 'href' and 'body'."""
description = """Performs a duckduckgo web search based on your query (think a Google search) then returns the top search results."""
inputs = {
"query": {"type": "string", "description": "The search query to perform."}
}
output_type = "any"
output_type = "string"

def __init__(self, *args, max_results=10, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
8 changes: 3 additions & 5 deletions src/smolagents/gradio_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
def pull_messages_from_step(step_log: AgentStep, test_mode: bool = True):
"""Extract ChatMessage objects from agent steps"""
if isinstance(step_log, ActionStep):
yield gr.ChatMessage(role="assistant", content=step_log.llm_output)
yield gr.ChatMessage(role="assistant", content=step_log.llm_output or "")
if step_log.tool_call is not None:
used_code = step_log.tool_call.name == "code interpreter"
content = step_log.tool_call.arguments
Expand All @@ -35,9 +35,7 @@ def pull_messages_from_step(step_log: AgentStep, test_mode: bool = True):
content=str(content),
)
if step_log.observations is not None:
yield gr.ChatMessage(
role="assistant", content=f"```\n{step_log.observations}\n```"
)
yield gr.ChatMessage(role="assistant", content=step_log.observations)
if step_log.error is not None:
yield gr.ChatMessage(
role="assistant",
Expand Down Expand Up @@ -65,7 +63,7 @@ def stream_to_gradio(
if isinstance(final_answer, AgentText):
yield gr.ChatMessage(
role="assistant",
content=f"**Final answer:**\n```\n{final_answer.to_string()}\n```",
content=f"**Final answer:**\n{final_answer.to_string()}\n",
)
elif isinstance(final_answer, AgentImage):
yield gr.ChatMessage(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def test_code_agent_missing_import_triggers_advice_in_error_log(self):
with console.capture() as capture:
agent.run("Count to 3")
str_output = capture.get()
assert "import under additional_authorized_imports" in str_output
assert "import under `additional_authorized_imports`" in str_output

def test_multiagents(self):
class FakeModelMultiagentsManagerAgent:
Expand Down
Loading