Agents

Agents use a Large Language Model (LLM) to take actions and return a response to an input. Agents have access to Tools, DocumentIndexes, and other Agents to complete their given task. AgentHQ is meant to make it easier for you to manage all these components and build something useful!

For more background on what Agents do, check out the LangChain docs. AgentHQ uses LangChain on the backend to build and run your agents.

Agent Types

SequentialChain Agent

This agent just takes your input and runs it through each block in the toolchain sequentially, passing the output of one tool as the input of the next. It’s predictable but not as flexible as the other agent types. Blocks can be any other agent, tool, or document index.

Sequential agents can maintain state throughout their run.

<aside> 💡 For now, this only applies to Custom Tools within the agent chain.

</aside>

When using a Custom Tool within a sequential agent, the tool will receive a local variable called agent_state

Custom tools can modify the agent state by just assigning a value to that variable. For example, here’s a tool that sets the agent state:

template = f"Classify the language of this text: {input} using a two-letter language code. Language Code:"
lang = llm(template)

template = f"Translate to English: {input}. English:"
english = llm(template)

agent_state = {"lang": lang.strip()}

result = english.strip()

The tool figures out what language the input is in, then assigns that to the agent_state['lang'] attribute. Then the tool translates the input into English and returns the result.

Futher along in the sequential agent, you could access this state and reference it. For example:

lang = agent_state['lang']
template = f"Translate this text into {lang}. Text: {input}. Translated:"

result = llm(template)