Skip to content

task

Class info

Classes

Name Children Inherits
Job
llmling_agent.models.task
A task is a piece of work that can be executed by an agent.
    Job
    llmling_agent.models.task
      Knowledge
      llmling_agent.models.knowledge
      Collection of context sources for an agent.
        ToolInfo
        llmling_agent.tools.base
        Information about a registered tool.

          🛈 DocStrings

          Job

          Bases: BaseModel

          A task is a piece of work that can be executed by an agent.

          Requirements: - The agent must have compatible dependencies (required_dependency) - The agent must produce the specified result type (required_return_type)

          Equipment: - The task provides necessary tools for execution (tools) - Tools are temporarily available during task execution

          Source code in src/llmling_agent/models/task.py
           21
           22
           23
           24
           25
           26
           27
           28
           29
           30
           31
           32
           33
           34
           35
           36
           37
           38
           39
           40
           41
           42
           43
           44
           45
           46
           47
           48
           49
           50
           51
           52
           53
           54
           55
           56
           57
           58
           59
           60
           61
           62
           63
           64
           65
           66
           67
           68
           69
           70
           71
           72
           73
           74
           75
           76
           77
           78
           79
           80
           81
           82
           83
           84
           85
           86
           87
           88
           89
           90
           91
           92
           93
           94
           95
           96
           97
           98
           99
          100
          101
          102
          103
          104
          105
          106
          107
          108
          109
          110
          111
          112
          113
          114
          115
          116
          117
          118
          119
          120
          class Job[TDeps, TResult](BaseModel):
              """A task is a piece of work that can be executed by an agent.
          
              Requirements:
              - The agent must have compatible dependencies (required_dependency)
              - The agent must produce the specified result type (required_return_type)
          
              Equipment:
              - The task provides necessary tools for execution (tools)
              - Tools are temporarily available during task execution
              """
          
              name: str | None = Field(None)
              """Technical identifier (automatically set from config key during registration)"""
          
              description: str | None = None
              """Human-readable description of what this task does"""
          
              prompt: str | ImportString[str] | BasePrompt
              """The task instruction/prompt."""
          
              required_return_type: ImportString[type[TResult]] = Field(
                  default="str", validate_default=True
              )  # type: ignore
              """Expected type of the task result."""
          
              required_dependency: ImportString[type[TDeps]] | None = Field(
                  default=None, validate_default=True
              )  # type: ignore
              """Dependencies or context data needed for task execution"""
          
              requires_vision: bool = False
              """Whether the agent requires vision"""
          
              knowledge: Knowledge | None = None
              """Optional knowledge sources for this task:
              - Simple file/URL paths
              - Rich resource definitions
              - Prompt templates
              """
          
              tools: list[ImportString | ToolConfig] = Field(default_factory=list)
              """Tools needed for this task."""
          
              min_context_tokens: int | None = None
              """Minimum amount of required context size."""
          
              model_config = ConfigDict(frozen=True, use_attribute_docstrings=True, extra="forbid")
          
              async def can_be_executed_by(self, agent: AnyAgent[Any, Any]) -> bool:
                  """Check if agent meets all requirements for this task."""
                  from llmling_agent.agent.structured import StructuredAgent
          
                  # Check dependencies
                  if self.required_dependency and not isinstance(
                      agent.context.data, self.required_dependency
                  ):
                      return False
          
                  # Check return type
                  if isinstance(agent, StructuredAgent):  # noqa: SIM102
                      if agent._result_type != self.required_return_type:  # type: ignore
                          return False
          
                  # Check vision capabilities
                  if self.requires_vision:  # noqa: SIM102
                      if not await agent.provider.supports_feature("vision"):
                          return False
          
                  return True
          
              @property
              def tool_configs(self) -> list[ToolConfig]:
                  """Get all tools as ToolConfig instances."""
                  return [
                      tool if isinstance(tool, ToolConfig) else ToolConfig(import_path=str(tool))
                      for tool in self.tools
                  ]
          
              async def get_prompt(self) -> str:
                  if isinstance(self.prompt, BasePrompt):
                      messages = await self.prompt.format()
                      return "\n\n".join(m.get_text_content() for m in messages)
                  return self.prompt
          
              def get_tools(self) -> list[ToolInfo]:
                  """Get all tools as ToolInfo instances."""
                  tools: list[ToolInfo] = []
                  for tool in self.tools:
                      match tool:
                          case str():
                              tools.append(ToolInfo.from_callable(tool))
                          case ToolConfig():
                              tools.append(ToolInfo.from_callable(tool.import_path))
                          case ToolInfo():
                              tools.append(tool)
                          case _:
                              msg = f"Invalid tool type: {type(tool)}"
                              raise ValueError(msg)
                  return tools
          

          description class-attribute instance-attribute

          description: str | None = None
          

          Human-readable description of what this task does

          knowledge class-attribute instance-attribute

          knowledge: Knowledge | None = None
          

          Optional knowledge sources for this task: - Simple file/URL paths - Rich resource definitions - Prompt templates

          min_context_tokens class-attribute instance-attribute

          min_context_tokens: int | None = None
          

          Minimum amount of required context size.

          name class-attribute instance-attribute

          name: str | None = Field(None)
          

          Technical identifier (automatically set from config key during registration)

          prompt instance-attribute

          prompt: str | ImportString[str] | BasePrompt
          

          The task instruction/prompt.

          required_dependency class-attribute instance-attribute

          required_dependency: ImportString[type[TDeps]] | None = Field(
              default=None, validate_default=True
          )
          

          Dependencies or context data needed for task execution

          required_return_type class-attribute instance-attribute

          required_return_type: ImportString[type[TResult]] = Field(
              default="str", validate_default=True
          )
          

          Expected type of the task result.

          requires_vision class-attribute instance-attribute

          requires_vision: bool = False
          

          Whether the agent requires vision

          tool_configs property

          tool_configs: list[ToolConfig]
          

          Get all tools as ToolConfig instances.

          tools class-attribute instance-attribute

          tools: list[ImportString | ToolConfig] = Field(default_factory=list)
          

          Tools needed for this task.

          can_be_executed_by async

          can_be_executed_by(agent: AnyAgent[Any, Any]) -> bool
          

          Check if agent meets all requirements for this task.

          Source code in src/llmling_agent/models/task.py
          70
          71
          72
          73
          74
          75
          76
          77
          78
          79
          80
          81
          82
          83
          84
          85
          86
          87
          88
          89
          90
          async def can_be_executed_by(self, agent: AnyAgent[Any, Any]) -> bool:
              """Check if agent meets all requirements for this task."""
              from llmling_agent.agent.structured import StructuredAgent
          
              # Check dependencies
              if self.required_dependency and not isinstance(
                  agent.context.data, self.required_dependency
              ):
                  return False
          
              # Check return type
              if isinstance(agent, StructuredAgent):  # noqa: SIM102
                  if agent._result_type != self.required_return_type:  # type: ignore
                      return False
          
              # Check vision capabilities
              if self.requires_vision:  # noqa: SIM102
                  if not await agent.provider.supports_feature("vision"):
                      return False
          
              return True
          

          get_tools

          get_tools() -> list[ToolInfo]
          

          Get all tools as ToolInfo instances.

          Source code in src/llmling_agent/models/task.py
          106
          107
          108
          109
          110
          111
          112
          113
          114
          115
          116
          117
          118
          119
          120
          def get_tools(self) -> list[ToolInfo]:
              """Get all tools as ToolInfo instances."""
              tools: list[ToolInfo] = []
              for tool in self.tools:
                  match tool:
                      case str():
                          tools.append(ToolInfo.from_callable(tool))
                      case ToolConfig():
                          tools.append(ToolInfo.from_callable(tool.import_path))
                      case ToolInfo():
                          tools.append(tool)
                      case _:
                          msg = f"Invalid tool type: {type(tool)}"
                          raise ValueError(msg)
              return tools