steamship.agents.schema package#

Submodules#

steamship.agents.schema.action module#

class steamship.agents.schema.action.Action(*, tool: Tool, input: List[Block], output: Optional[List[Block]] = [])[source]#

Bases: BaseModel

Actions represent a binding of a Tool to the inputs supplied to the tool.

Upon completion, the Action also contains the output of the Tool given the inputs.

input: List[Block]#

Data provided directly to the Tool (full context is passed in run).

output: Optional[List[Block]]#

Any direct output produced by the Tool.

tool: Tool#

Tool used by this action.

class steamship.agents.schema.action.AgentTool(*, name: str = 'Agent', agent_description: str = '', human_description: str = 'Placeholder tool object for FinishAction')[source]#

Bases: Tool

run(tool_input: List[Block], context: AgentContext) Union[List[Block], Task[Any]][source]#

Run the tool given the provided input and context.

At the moment, only synchronous Tools (those that return List[Block]) are supported.

Support for asynchronous Tools (those that return Task[Any]) will be added shortly.

class steamship.agents.schema.action.FinishAction(*, tool: Tool = AgentTool(name='Agent', agent_description='', human_description='Placeholder tool object for FinishAction'), input: List[Block] = [], output: Optional[List[Block]] = [])[source]#

Bases: Action

Represents a final selected action in an Agent Execution.

input: List[Block]#

Data provided directly to the Tool (full context is passed in run).

tool: Tool#

Tool used by this action.

steamship.agents.schema.agent module#

class steamship.agents.schema.agent.Agent(*, tools: List[Tool])[source]#

Bases: BaseModel, ABC

Agent is responsible for choosing the next action to take for an AgentService.

It uses the provided context, and a set of Tools, to decide on an action that will be executed by the AgentService.

abstract next_action(context: AgentContext) Action[source]#
tools: List[Tool]#

Tools that can be used by the Agent in selecting the next Action.

class steamship.agents.schema.agent.LLMAgent(*, tools: List[Tool], llm: LLM, output_parser: OutputParser)[source]#

Bases: Agent

LLMAgents choose next actions for an AgentService based on interactions with an LLM.

llm: LLM#

The LLM to use for action selection.

abstract next_action(context: AgentContext) Action[source]#
output_parser: OutputParser#

Utility responsible for converting LLM output into Actions

steamship.agents.schema.context module#

class steamship.agents.schema.context.AgentContext[source]#

Bases: object

AgentContext contains all relevant information about a particular execution of an Agent. It is used by the AgentService to manage execution history as well as store/retrieve information and metadata that will be used in the process of an agent execution.

chat_history: ChatHistory#

Record of user-package messages. It records user submitted queries/prompts and the final agent-driven answer sent in response to those queries/prompts. It does NOT record any chat history related to agent execution and action selection.

client: Steamship#

Provides workspace-specific utilities for the agents and tools.

completed_steps: List[Action] = []#

Record of agent-selected Actions and their outputs. This provides an ordered look at the execution sequence for this context.

emit_funcs: List[Callable[[List[Block], Dict[str, Any]], None]] = []#

Called when an agent execution has completed. These provide a way for the AgentService to return the result of an agent execution to the package that requested the agent execution.

static get_or_create(client: Steamship, context_keys: Dict[str, str], tags: Optional[List[Tag]] = None)[source]#
property id: str#
metadata: Dict[str, Any] = {}#

Allows storage of arbitrary information that may be useful for agents and tools.

steamship.agents.schema.llm module#

class steamship.agents.schema.llm.LLM[source]#

Bases: BaseModel, ABC

LLM wraps large language model-based backends.

They may be used with LLMAgents in Action selection, or for direct prompt completion.

abstract complete(prompt: str, stop: Optional[str] = None) List[Block][source]#

Completes the provided prompt, stopping when the stop sequeunce is found.

steamship.agents.schema.output_parser module#

class steamship.agents.schema.output_parser.OutputParser[source]#

Bases: BaseModel, ABC

Used to convert text into Actions.

Primarily used by LLM-based agents that generate textual descriptions of selected actions and their inputs. OutputParsers can be used to convert those descriptions into Action objects for the AgentService to run.

Example

  • input: “Action: GenerateImage

    ActionInput: row-house”

  • output: Action(“dalle”, “row-house”)

abstract parse(text: str, context: AgentContext) Action[source]#

Convert text into an Action object.

steamship.agents.schema.tool module#

class steamship.agents.schema.tool.AgentContext[source]#

Bases: BaseModel

Placeholder to avoid circular dependency.

class steamship.agents.schema.tool.Tool(*, name: str, agent_description: str, human_description: str)[source]#

Bases: BaseModel

Tools provide functionality that may be used by AgentServices, as directed by Agents, to achieve a goal.

Tools may be used to wrap Steamship packages and plugins, as well as third-party backend services, and even locally-contained bits of Python code.

agent_description: str#

Description for use in an agent in order to enable Action selection. It should include a short summary of what the Tool does, what the inputs to the Tool should be, and what the outputs of the tool are.

human_description: str#

Human-friendly description. Used for logging, tool indices, etc.

name: str#

The short name for the tool. This will be used by Agents to refer to this tool during action selection.

post_process(async_task: Task, context: AgentContext) List[Block][source]#

Transforms Task output into a List[Block].

abstract run(tool_input: List[Block], context: AgentContext) Union[List[Block], Task[Any]][source]#

Run the tool given the provided input and context.

At the moment, only synchronous Tools (those that return List[Block]) are supported.

Support for asynchronous Tools (those that return Task[Any]) will be added shortly.

Module contents#

class steamship.agents.schema.Action(*, tool: Tool, input: List[Block], output: Optional[List[Block]] = [])[source]#

Bases: BaseModel

Actions represent a binding of a Tool to the inputs supplied to the tool.

Upon completion, the Action also contains the output of the Tool given the inputs.

input: List[Block]#

Data provided directly to the Tool (full context is passed in run).

output: Optional[List[Block]]#

Any direct output produced by the Tool.

tool: Tool#

Tool used by this action.

class steamship.agents.schema.Agent(*, tools: List[Tool])[source]#

Bases: BaseModel, ABC

Agent is responsible for choosing the next action to take for an AgentService.

It uses the provided context, and a set of Tools, to decide on an action that will be executed by the AgentService.

abstract next_action(context: AgentContext) Action[source]#
tools: List[Tool]#

Tools that can be used by the Agent in selecting the next Action.

class steamship.agents.schema.AgentContext[source]#

Bases: object

AgentContext contains all relevant information about a particular execution of an Agent. It is used by the AgentService to manage execution history as well as store/retrieve information and metadata that will be used in the process of an agent execution.

chat_history: ChatHistory#

Record of user-package messages. It records user submitted queries/prompts and the final agent-driven answer sent in response to those queries/prompts. It does NOT record any chat history related to agent execution and action selection.

client: Steamship#

Provides workspace-specific utilities for the agents and tools.

completed_steps: List[Action] = []#

Record of agent-selected Actions and their outputs. This provides an ordered look at the execution sequence for this context.

emit_funcs: List[Callable[[List[Block], Dict[str, Any]], None]] = []#

Called when an agent execution has completed. These provide a way for the AgentService to return the result of an agent execution to the package that requested the agent execution.

static get_or_create(client: Steamship, context_keys: Dict[str, str], tags: Optional[List[Tag]] = None)[source]#
property id: str#
metadata: Dict[str, Any] = {}#

Allows storage of arbitrary information that may be useful for agents and tools.

class steamship.agents.schema.FinishAction(*, tool: Tool = AgentTool(name='Agent', agent_description='', human_description='Placeholder tool object for FinishAction'), input: List[Block] = [], output: Optional[List[Block]] = [])[source]#

Bases: Action

Represents a final selected action in an Agent Execution.

input: List[Block]#

Data provided directly to the Tool (full context is passed in run).

output: Optional[List[Block]]#

Any direct output produced by the Tool.

tool: Tool#

Tool used by this action.

class steamship.agents.schema.LLM[source]#

Bases: BaseModel, ABC

LLM wraps large language model-based backends.

They may be used with LLMAgents in Action selection, or for direct prompt completion.

abstract complete(prompt: str, stop: Optional[str] = None) List[Block][source]#

Completes the provided prompt, stopping when the stop sequeunce is found.

class steamship.agents.schema.LLMAgent(*, tools: List[Tool], llm: LLM, output_parser: OutputParser)[source]#

Bases: Agent

LLMAgents choose next actions for an AgentService based on interactions with an LLM.

llm: LLM#

The LLM to use for action selection.

abstract next_action(context: AgentContext) Action[source]#
output_parser: OutputParser#

Utility responsible for converting LLM output into Actions

tools: List[Tool]#

Tools that can be used by the Agent in selecting the next Action.

class steamship.agents.schema.OutputParser[source]#

Bases: BaseModel, ABC

Used to convert text into Actions.

Primarily used by LLM-based agents that generate textual descriptions of selected actions and their inputs. OutputParsers can be used to convert those descriptions into Action objects for the AgentService to run.

Example

  • input: “Action: GenerateImage

    ActionInput: row-house”

  • output: Action(“dalle”, “row-house”)

abstract parse(text: str, context: AgentContext) Action[source]#

Convert text into an Action object.

class steamship.agents.schema.Tool(*, name: str, agent_description: str, human_description: str)[source]#

Bases: BaseModel

Tools provide functionality that may be used by AgentServices, as directed by Agents, to achieve a goal.

Tools may be used to wrap Steamship packages and plugins, as well as third-party backend services, and even locally-contained bits of Python code.

agent_description: str#

Description for use in an agent in order to enable Action selection. It should include a short summary of what the Tool does, what the inputs to the Tool should be, and what the outputs of the tool are.

human_description: str#

Human-friendly description. Used for logging, tool indices, etc.

name: str#

The short name for the tool. This will be used by Agents to refer to this tool during action selection.

post_process(async_task: Task, context: AgentContext) List[Block][source]#

Transforms Task output into a List[Block].

abstract run(tool_input: List[Block], context: AgentContext) Union[List[Block], Task[Any]][source]#

Run the tool given the provided input and context.

At the moment, only synchronous Tools (those that return List[Block]) are supported.

Support for asynchronous Tools (those that return Task[Any]) will be added shortly.