Skip to main content

A human in the loop tool to refine queries. For use with haystack agents

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

haystack_human_tool-0.2.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

haystack_human_tool-0.2.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file haystack_human_tool-0.2.0.tar.gz.

File metadata

  • Download URL: haystack_human_tool-0.2.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for haystack_human_tool-0.2.0.tar.gz
Algorithm Hash digest
SHA256 729bf70b86407f3a1f8cbce39cd6ee147e40d6b4eaa44cf75f6b3ceb57fde29a
MD5 228f2c330e69aa7fce302ce4323fdd8a
BLAKE2b-256 cd951ba801da370d1cf90154134f881eff16fd91dbef931c0424ca18cb863b96

See more details on using hashes here.

File details

Details for the file haystack_human_tool-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for haystack_human_tool-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2bc5db672665148c5e3346b7579d162e5b5e7930085ea0f32bc87d89d904400e
MD5 79e010a61e5bef85ab09efe4400f1b01
BLAKE2b-256 8d770a5383ed674d77213ced916aa9f10fb2f995cc5fd20d291aec6b7e7053eb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page