Skip to content

Commit 1dcc694

Browse files
docs: sync Haystack API reference on Docusaurus (#12003)
Co-authored-by: anakin87 <44616784+anakin87@users.noreply.github.com>
1 parent 2618dae commit 1dcc694

4 files changed

Lines changed: 30 additions & 7 deletions

File tree

docs-website/reference/haystack-api/hooks_api.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,29 @@ paths, construct a `FunctionHook` directly with both `function` and `async_funct
110110

111111
```python
112112
from haystack.components.agents import Agent
113+
from haystack.components.generators.chat import OpenAIChatGenerator
113114
from haystack.hooks import hook
114115
from haystack.components.agents.state import State
115116
from haystack.dataclasses import ChatMessage
117+
from haystack.tools import tool
118+
119+
@tool
120+
def weather_tool(city: str) -> str:
121+
'''Get the current weather for a given city.'''
122+
return f"The weather in {city} is sunny."
123+
124+
@tool
125+
def save(content: str) -> str:
126+
'''Save content to durable storage.'''
127+
return "Saved."
116128

117129
@hook
118130
def require_save(state: State) -> None:
119131
if state.get("tool_call_counts", {}).get("save", 0) == 0:
120132
state.set("messages", [ChatMessage.from_system("You must call `save` before finishing.")])
121133
state.set("continue_run", True)
122134

123-
agent = Agent(chat_generator=..., tools=[...], hooks={"on_exit": [require_save]})
135+
agent = Agent(chat_generator=OpenAIChatGenerator(), tools=[weather_tool, save], hooks={"on_exit": [require_save]})
124136
```
125137

126138
**Parameters:**
@@ -199,6 +211,8 @@ Register it on an `Agent` to confirm, modify, or reject tool calls before they r
199211

200212
```python
201213
from haystack.components.agents import Agent
214+
from haystack.components.generators.chat import OpenAIChatGenerator
215+
from haystack.tools import tool
202216
from haystack.hooks.human_in_the_loop import (
203217
AlwaysAskPolicy,
204218
BlockingConfirmationStrategy,
@@ -208,14 +222,19 @@ from haystack.hooks.human_in_the_loop import (
208222
SimpleConsoleUI,
209223
)
210224

225+
@tool
226+
def delete_file(path: str) -> str:
227+
'''Delete the file at the given path.'''
228+
return f"Deleted {path}."
229+
211230
hook = ConfirmationHook(
212231
confirmation_strategies={
213-
"my_tool": BlockingConfirmationStrategy(
232+
"delete_file": BlockingConfirmationStrategy(
214233
confirmation_policy=NeverAskPolicy(), confirmation_ui=SimpleConsoleUI()
215234
)
216235
}
217236
)
218-
agent = Agent(chat_generator=..., tools=[...], hooks={"before_tool": [hook]})
237+
agent = Agent(chat_generator=OpenAIChatGenerator(), tools=[delete_file], hooks={"before_tool": [hook]})
219238
```
220239

221240
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
652671
the full result. Register it on an `Agent` under the `after_tool` hook point. Which tools offload, and under what
653672
condition, is controlled per tool by `offload_strategies`:
654673

674+
<!-- test-concept -->
675+
655676
```python
656677
from haystack.components.agents import Agent
657678
from haystack.components.generators.chat import OpenAIChatGenerator

docs-website/reference/haystack-api/joiners_api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ p.add_component(instance=InMemoryEmbeddingRetriever(document_store=document_stor
321321
p.add_component(instance=DocumentJoiner(), name="joiner")
322322
p.connect("bm25_retriever", "joiner")
323323
p.connect("embedding_retriever", "joiner")
324-
p.connect("text_embedder", "embedding_retriever")
324+
p.connect("text_embedder.embedding", "embedding_retriever.query_embedding")
325325
query = "What is the capital of France?"
326326
p.run(data={"query": query, "text": query, "top_k": 1})
327327
```
@@ -452,8 +452,8 @@ pipe.connect("feedback_prompt_builder.prompt", "feedback_llm.messages")
452452
pipe.connect("feedback_llm.replies", "list_joiner")
453453

454454
query = "What is nuclear physics?"
455-
ans = pipe.run(data={"prompt_builder": {"template_variables":{"query": query}},
456-
"feedback_prompt_builder": {"template_variables":{"query": query}}})
455+
ans = pipe.run(data={"prompt_builder": {"query": query},
456+
"feedback_prompt_builder": {"query": query}})
457457

458458
print(ans["list_joiner"]["values"])
459459
```

docs-website/reference/haystack-api/routers_api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ This component can be used with general-purpose LLMs and with specialized LLMs f
593593
### Usage example
594594

595595
```python
596-
from haystack.components.generators.chat import HuggingFaceAPIChatGenerator
596+
from haystack_integrations.components.generators.huggingface_api import HuggingFaceAPIChatGenerator
597597
from haystack.components.routers.llm_messages_router import LLMMessagesRouter
598598
from haystack.dataclasses import ChatMessage
599599

docs-website/reference/haystack-api/tools_api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,8 @@ A skill is a directory (or equivalent storage unit) containing a `SKILL.md` file
832832

833833
### Usage example
834834

835+
<!-- test-concept -->
836+
835837
```python
836838
from haystack.components.agents import Agent
837839
from haystack.components.generators.chat import OpenAIChatGenerator

0 commit comments

Comments
 (0)