跳到正文
LangChain:Blog·· 3 小时前AI 评分40

LangChain 如何用 Managed Deep Agents 打造开箱即用的智能体用户体验

How to build great out-of-the-box user experiences with Managed Deep Agents

AI 导读

LangChain 在 Managed Deep Agents v0.9 中新增 reactions API,可为 Slack 等渠道的分布式智能体动态分配 emoji 回应,支持字符串或返回 emoji 的可调用对象。该功能可接入 Jev 等决策模型,Jev 最多支持 255 个选项,并可用置信度阈值(低于 0.25 时回退到 👀)控制回应。

正文

Loading states are one of the most underrated (and forgotten) design aspects when building effective agent user experiences.

In our experience, users trust agents when they have visibility into what these agents are actually doing. This behavior is showing up more in the form of skeuomorphic UI, a design concept where digital objects imitate real-world counterparts. The visionary Domino’s Pizza Tracker is one of the most prominent examples of skeuomorphic design that could be applied to agents. Today, digital loading states (even ones that may lie to you) are crucial for making any user experience understandable and effective. The new agent reactions SDK for Managed Deep Agents is a great tool to build delightful interfaces and loading states for users interacting with your agents.

New reactions attribute in Managed Deep Agents

In v0.9, Managed Deep Agents includes a new API for managing reactions for your distributed agents, and a system to dynamically assign emoji responses with your instrument of choice, such as decision models, frontier models, or good old-fashioned if statements.

The new reactions attribute for Slack channels accepts either a string representing an emoji or a callable that returns one:

from managed_deepagents import channels

async def choose_emoji(context: dict) -> str:
    return "bug" if "broken" in context["text"].lower() else "eyes"

channel = channels.slack(name="Support Bot", reactions=choose_emoji)

In this example, we default to 👀, but static analysis will assign a 🐛 if a message includes the word “broken.”

We want LangChain developers to be able to adopt common patterns of user delight in loading states and waiting patterns, as many agent tasks can run over long periods of time. End users interacting with agents need acknowledgment that the task has been received.

For example, we recently launched an internal marketing agent to create video content. While waiting for the agent to reply, it's helpful for users to understand the agent's progress.

Here's an example of the the type of video and motion graphic content our agent can create:

‍

It’s often not sufficient to simply respond to a message with a single emoji. We also need agents to tell the user how they interpreted the task, and the contextual response can be a key part of the design of your agent.

Let’s take the basic reaction example further. We can have a decision model, like Jev, choose across a set vocabulary of emojis based on the input context. Jev supports up to 255 choices, but you could construct a decision matrix with multiple questions (for example, by grouping emojis into categories and asking Jev to choose a category, then an emoji) to query over more emojis:

from functools import lru_cache

from langchain_typesafe import Choice, TypeSafeClassifier
from managed_deepagents import channels

# The description is what the model matches on, so describe the situation
# rather than the picture. Keep an option for anything unremarkable.
VOCABULARY = Choice(
    instructions="Which emoji best acknowledges this message?",
    criteria={ 
        "bug": "A defect or incorrect behaviour.",
        "rotating_light": "A declared incident or outage.",
        "mag": "A code review, pull request, or diff to look at.",
        "hourglass": "Waiting on someone or something else; blocked.",
        "speech_balloon": "A question, or a request to explain something.",
        "wave": "A greeting or hello.",
        "eyes": "Anything that does not clearly fit another option.",
    },
)


@lru_cache(maxsize=1)
def classifier() -> TypeSafeClassifier:
    return TypeSafeClassifier(model="typesafe/jev-latest")


async def choose_emoji(context: dict) -> str:
    answer = await classifier().ainvoke(
        {"state": context["text"][:2000], "questions": {"emoji": VOCABULARY}}
    )
    emoji = answer.choices["emoji"]
    # Below this the model has no real view, so prefer a generic reaction.
    return emoji.choice if emoji.confidence >= 0.25 else "eyes"


channel = channels.slack(name="Support Bot", reactions=choose_emoji)

In this example, we’re using the new TypeSafe Classifier that’s part of the LangChain toolkit. It’s a great way to interact with TypeSafe-compatible decision models, like Jev, but it’s also possible to use other decision models with the same endpoints, like SemIf, hosted on LangSmith LLM Gateway. Or, swap between models to experiment with the best option.

The same emoji can mean opposite things depending on what the agent does. For example, 🔥 from an on-call agent could mean production is burning and you should wake up. 🔥 from a growth agent could mean that the campaign is working and you can go back to sleep. This is why the criteria descriptions do more work than the emoji names. The model matches on your description of the situation, so the same glyph carries whatever meaning your workspace already gives it.

The above example also shows you can leverage confidence thresholds. If the decision model is less than 25% confident in its top pick, we’ll fall back to 👀.  You could also fall back to no reaction if none of the emojis you’ve provided in a vocabulary are properly suited.

You could argue that there is dishonesty to this design: Because a different model is scoring the reaction response from the model responding, there may be subtle differences in interpretation. For this reason, it's important to write effective descriptions of how you expect each reaction to be used. A scoring model will over-index on certain reaction responses if their description is overly generic, even if a different reaction would not overfit to an untrained eye.

You can add custom emojis to your vocabulary by Slack shortcode. For our internal content agent, the applied AI team created a set of custom emojis the agent can use in replies. I’m a fan of the lc-no-em-dash, which the agent chooses when instructed to write content:

Experiment with different approaches. Different descriptions for emojis (or different ways of structuring your vocabulary entirely) will lead to different results. Similarly, expand or contract the set of emojis an agent has at its disposal.

Managed Deep Agents are designed to leverage all the subtle design interfaces we think are crucial to agent adoption with simple, expressive APIs. Get started adding reactions for your existing Managed Deep Agents using our documentation. Or, if you haven’t built a managed deep agent before, the best place to get started is our quickstart.

‍

来源:LangChain:Blog · langchain.com