跳过内容

方法

__init__(**kwargs)

创建一个新的 Agent。

参数

名称 类型 描述 默认值
kwargs

传递给底层 Agent 后端和 LLM 管道实例的参数

{}
源代码位于 txtai/agent/base.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def __init__(self, **kwargs):
    """
    Creates a new Agent.

    Args:
        kwargs: arguments to pass to the underlying Agent backend and LLM pipeline instance
    """

    # Ensure backwards compatibility
    if "max_iterations" in kwargs:
        kwargs["max_steps"] = kwargs.pop("max_iterations")

    # Create agent process runner
    self.process = ProcessFactory.create(kwargs)

    # Tools dictionary
    self.tools = self.process.tools

__call__(text, maxlength=8192, stream=False, **kwargs)

运行 Agent 循环。

参数

名称 类型 描述 默认值
text

要运行的指令

必需
maxlength

最大序列长度

8192
stream

如果为 True 则流式传输响应,默认为 False

False
kwargs

额外的关键字参数

{}

返回值

类型 描述

结果

源代码位于 txtai/agent/base.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def __call__(self, text, maxlength=8192, stream=False, **kwargs):
    """
    Runs an agent loop.

    Args:
        text: instructions to run
        maxlength: maximum sequence length
        stream: stream response if True, defaults to False
        kwargs: additional keyword arguments

    Returns:
        result
    """

    # Process parameters
    self.process.model.parameters(maxlength)

    # Run agent loop
    return self.process.run(text, stream=stream, **kwargs)