Skip to main content

Haystack Human In Loop Tool

Human in Loop tool for haystack Agents. Uses human guidance to refine queries and improve performance.

Installation

  • Python pip: python3 -m pip install haystack-human-tool . This package will attempt to install the dependencies (farm-haystack>=1.15.0, redis, haystack-memory, bleach)
  • Python pip (skip dependency installation: Use python3 -m pip install haystack-human-tool --no-deps
  • Using git: pip install git+https://github.com/rolandtannous/haystack-human-tool.git@main#egg=haystack-human-tool

Usage

To use the human in the loop tool in your agent, you need three core components:

  • haystack-memory: This is the memory library for haystack agents. It provides access to working and sensory memories.
  • HumanInLoopNode: This node adds human in the loop to the agent as a tool. It allows the agent to seek guidance from the human user in order to refine the user query.
  • sensory-memory: This is an in-memory implementation that mimics a human's brief sensory memory, lasting only for the duration of one interaction.
from haystack.agents import Agent, Tool
from haystack.nodes import PromptNode
from haystack_memory.memory import MemoryRecallNode
from haystack_memory.utils import MemoryUtils
from haystack_human_tool.humaninloop import HumanInLoopNode
from haystack_human_tool.prompt_templates import agent_template

# Initialize the memory and the memory tool so the agent can retrieve the memory
sensory_memory = []
working_memory = []
memory_node = MemoryRecallNode(memory=working_memory)
memory_tool = Tool(name="Memory",
                   pipeline_or_node=memory_node,
                   description="Your memory. Always access this tool first to remember what you have learned.")

human_node = HumanInLoopNode(sensory_memory=sensory_memory)
human_tool = Tool(name="Human",
                  pipeline_or_node=human_node,
                  description="Access this tool to refine your query. Ask the human to rephrase the question or to explain what or who the human is referring to. Use the human's answer to rephrase your query for use as input to other tools")

prompt_node = PromptNode(model_name_or_path="text-davinci-003", 
                         api_key="<YOUR_OPENAI_KEY>", 
                         max_length=1024,
                         stop_words=["Observation:"])
memory_agent = Agent(prompt_node=prompt_node, prompt_template=agent_template)
memory_agent.add_tool(memory_tool)
memory_agent.add_tool(human_tool)

# Initialize the utils to save the query and the answers to the memory
memory_utils = MemoryUtils(working_memory=working_memory, sensory_memory=sensory_memory, agent=memory_agent)
result = memory_utils.chat("<Your Question>")

Example

An Example can be found in the examples/ folder. It contains the usage for all memory types. To open the example in colab, click on the following links:

  • Human in Tool powered agent: Open In Colab

Metadata

Release files for haystack-human-tool 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for haystack-human-tool 0.2.0
File Size Uploaded
haystack_human_tool-0.2.0.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for haystack-human-tool 0.2.0
File Interpreter ABI Platform
haystack_human_tool-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.6 kB

Release files / haystack_human_tool-0.2.0.tar.gz

Download URL haystack_human_tool-0.2.0.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
729bf70b86407f3a1f8cbce39cd6ee147e40d6b4eaa44cf75f6b3ceb57fde29a
BLAKE2b-256 checksum
How to use checksums
cd951ba801da370d1cf90154134f881eff16fd91dbef931c0424ca18cb863b96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release files / haystack_human_tool-0.2.0-py3-none-any.whl

Download URL haystack_human_tool-0.2.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2bc5db672665148c5e3346b7579d162e5b5e7930085ea0f32bc87d89d904400e
BLAKE2b-256 checksum
How to use checksums
8d770a5383ed674d77213ced916aa9f10fb2f995cc5fd20d291aec6b7e7053eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page