diff --git a/docs-website/reference/haystack-api/hooks_api.md b/docs-website/reference/haystack-api/hooks_api.md index 3d02aabaa45..4a7a3f61061 100644 --- a/docs-website/reference/haystack-api/hooks_api.md +++ b/docs-website/reference/haystack-api/hooks_api.md @@ -110,9 +110,21 @@ paths, construct a `FunctionHook` directly with both `function` and `async_funct ```python from haystack.components.agents import Agent +from haystack.components.generators.chat import OpenAIChatGenerator from haystack.hooks import hook from haystack.components.agents.state import State from haystack.dataclasses import ChatMessage +from haystack.tools import tool + +@tool +def weather_tool(city: str) -> str: + '''Get the current weather for a given city.''' + return f"The weather in {city} is sunny." + +@tool +def save(content: str) -> str: + '''Save content to durable storage.''' + return "Saved." @hook def require_save(state: State) -> None: @@ -120,7 +132,7 @@ def require_save(state: State) -> None: state.set("messages", [ChatMessage.from_system("You must call `save` before finishing.")]) state.set("continue_run", True) -agent = Agent(chat_generator=..., tools=[...], hooks={"on_exit": [require_save]}) +agent = Agent(chat_generator=OpenAIChatGenerator(), tools=[weather_tool, save], hooks={"on_exit": [require_save]}) ``` **Parameters:** @@ -199,6 +211,8 @@ Register it on an `Agent` to confirm, modify, or reject tool calls before they r ```python from haystack.components.agents import Agent +from haystack.components.generators.chat import OpenAIChatGenerator +from haystack.tools import tool from haystack.hooks.human_in_the_loop import ( AlwaysAskPolicy, BlockingConfirmationStrategy, @@ -208,14 +222,19 @@ from haystack.hooks.human_in_the_loop import ( SimpleConsoleUI, ) +@tool +def delete_file(path: str) -> str: + '''Delete the file at the given path.''' + return f"Deleted {path}." + hook = ConfirmationHook( confirmation_strategies={ - "my_tool": BlockingConfirmationStrategy( + "delete_file": BlockingConfirmationStrategy( confirmation_policy=NeverAskPolicy(), confirmation_ui=SimpleConsoleUI() ) } ) -agent = Agent(chat_generator=..., tools=[...], hooks={"before_tool": [hook]}) +agent = Agent(chat_generator=OpenAIChatGenerator(), tools=[delete_file], hooks={"before_tool": [hook]}) ``` A key may be a single tool name, a tuple of tool names sharing one strategy, or the wildcard `"*"` which applies @@ -652,6 +671,8 @@ This `after_tool` Agent hook writes the full result to the store so the next LLM the full result. Register it on an `Agent` under the `after_tool` hook point. Which tools offload, and under what condition, is controlled per tool by `offload_strategies`: + + ```python from haystack.components.agents import Agent from haystack.components.generators.chat import OpenAIChatGenerator diff --git a/docs-website/reference/haystack-api/joiners_api.md b/docs-website/reference/haystack-api/joiners_api.md index b0517e2cec7..fb6d205bf62 100644 --- a/docs-website/reference/haystack-api/joiners_api.md +++ b/docs-website/reference/haystack-api/joiners_api.md @@ -321,7 +321,7 @@ p.add_component(instance=InMemoryEmbeddingRetriever(document_store=document_stor p.add_component(instance=DocumentJoiner(), name="joiner") p.connect("bm25_retriever", "joiner") p.connect("embedding_retriever", "joiner") -p.connect("text_embedder", "embedding_retriever") +p.connect("text_embedder.embedding", "embedding_retriever.query_embedding") query = "What is the capital of France?" p.run(data={"query": query, "text": query, "top_k": 1}) ``` @@ -452,8 +452,8 @@ pipe.connect("feedback_prompt_builder.prompt", "feedback_llm.messages") pipe.connect("feedback_llm.replies", "list_joiner") query = "What is nuclear physics?" -ans = pipe.run(data={"prompt_builder": {"template_variables":{"query": query}}, - "feedback_prompt_builder": {"template_variables":{"query": query}}}) +ans = pipe.run(data={"prompt_builder": {"query": query}, + "feedback_prompt_builder": {"query": query}}) print(ans["list_joiner"]["values"]) ``` diff --git a/docs-website/reference/haystack-api/routers_api.md b/docs-website/reference/haystack-api/routers_api.md index b42fcb668b1..25c2efb1537 100644 --- a/docs-website/reference/haystack-api/routers_api.md +++ b/docs-website/reference/haystack-api/routers_api.md @@ -593,7 +593,7 @@ This component can be used with general-purpose LLMs and with specialized LLMs f ### Usage example ```python -from haystack.components.generators.chat import HuggingFaceAPIChatGenerator +from haystack_integrations.components.generators.huggingface_api import HuggingFaceAPIChatGenerator from haystack.components.routers.llm_messages_router import LLMMessagesRouter from haystack.dataclasses import ChatMessage diff --git a/docs-website/reference/haystack-api/tools_api.md b/docs-website/reference/haystack-api/tools_api.md index 0ebd08b67ff..bb95ca91dc6 100644 --- a/docs-website/reference/haystack-api/tools_api.md +++ b/docs-website/reference/haystack-api/tools_api.md @@ -832,6 +832,8 @@ A skill is a directory (or equivalent storage unit) containing a `SKILL.md` file ### Usage example + + ```python from haystack.components.agents import Agent from haystack.components.generators.chat import OpenAIChatGenerator