Skip to content

base

Class info

Classes

Name Children Inherits
ResourceProvider
llmling_agent.resource_providers.base
Base class for resource providers.
Tool
llmling_agent.tools.base
Information about a registered tool.
    ToolHints
    llmling_agent_config.tools
    Configuration for tool execution hints.

      🛈 DocStrings

      Base resource provider interface.

      ResourceProvider

      Base class for resource providers.

      Provides tools, prompts, and other resources to agents. Default implementations return empty lists - override as needed.

      Source code in src/llmling_agent/resource_providers/base.py
       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
      121
      122
      123
      124
      125
      126
      127
      128
      129
      130
      131
      132
      133
      134
      135
      136
      137
      138
      139
      140
      141
      142
      143
      144
      145
      146
      147
      148
      149
      150
      151
      152
      153
      154
      155
      156
      157
      158
      159
      160
      161
      162
      163
      164
      165
      166
      167
      168
      169
      170
      171
      172
      class ResourceProvider:
          """Base class for resource providers.
      
          Provides tools, prompts, and other resources to agents.
          Default implementations return empty lists - override as needed.
          """
      
          def __init__(self, name: str, owner: str | None = None) -> None:
              """Initialize the resource provider."""
              self.name = name
              self.owner = owner
              self.log = logger.bind(name=self.name, owner=self.owner)
      
          async def __aenter__(self) -> Self:
              """Async context entry if required."""
              return self
      
          async def __aexit__(
              self,
              exc_type: type[BaseException] | None,
              exc_val: BaseException | None,
              exc_tb: TracebackType | None,
          ) -> None:
              """Async context cleanup if required."""
      
          def __repr__(self) -> str:
              return f"{self.__class__.__name__}(name={self.name!r})"
      
          async def get_tools(self) -> list[Tool]:
              """Get available tools. Override to provide tools."""
              return []
      
          async def get_tool(self, tool_name: str) -> Tool:
              """Get specific tool."""
              tools = await self.get_tools()
              for tool in tools:
                  if tool.name == tool_name:
                      return tool
              msg = f"Tool {tool_name!r} not found"
              raise ValueError(msg)
      
          async def get_prompts(self) -> list[BasePrompt]:
              """Get available prompts. Override to provide prompts."""
              return []
      
          async def get_resources(self) -> list[ResourceInfo]:
              """Get available resources. Override to provide resources."""
              return []
      
          async def get_skills(self) -> list[Skill]:
              """Get available skills. Override to provide skills."""
              return []
      
          async def get_skill_instructions(self, skill_name: str) -> str:
              """Get full instructions for a specific skill.
      
              Args:
                  skill_name: Name of the skill to get instructions for
      
              Returns:
                  The full skill instructions for execution
      
              Raises:
                  KeyError: If skill not found
              """
              msg = f"Skill {skill_name!r} not found"
              raise KeyError(msg)
      
          async def get_request_parts(
              self, name: str, arguments: dict[str, str] | None = None
          ) -> list[ModelRequestPart]:
              """Get a prompt formatted with arguments.
      
              Args:
                  name: Name of the prompt to format
                  arguments: Optional arguments for prompt formatting
      
              Returns:
                  Single chat message with merged content
      
              Raises:
                  KeyError: If prompt not found
                  ValueError: If formatting fails
              """
              prompts = await self.get_prompts()
              prompt = next((p for p in prompts if p.name == name), None)
              if not prompt:
                  msg = f"Prompt {name!r} not found"
                  raise KeyError(msg)
      
              messages = await prompt.format(arguments or {})
              if not messages:
                  msg = f"Prompt {name!r} produced no messages"
                  raise ValueError(msg)
      
              return [p for prompt_msg in messages for p in prompt_msg.to_pydantic_parts()]
      
          def create_tool(
              self,
              fn: Callable[..., Any],
              read_only: bool | None = None,
              destructive: bool | None = None,
              idempotent: bool | None = None,
              open_world: bool | None = None,
              requires_confirmation: bool = False,
              metadata: dict[str, Any] | None = None,
              category: ToolKind | None = None,
              name_override: str | None = None,
              description_override: str | None = None,
              schema_override: OpenAIFunctionDefinition | None = None,
          ) -> Tool:
              """Create a tool from a function.
      
              Args:
                  fn: Function to create a tool from
                  read_only: Whether the tool is read-only
                  destructive: Whether the tool is destructive
                  idempotent: Whether the tool is idempotent
                  open_world: Whether the tool is open-world
                  requires_confirmation: Whether the tool requires confirmation
                  metadata: Metadata for the tool
                  category: Category of the tool
                  name_override: Override the name of the tool
                  description_override: Override the description of the tool
                  schema_override: Override the schema of the tool
      
              Returns:
                  Tool created from the function
              """
              return Tool.from_callable(
                  fn=fn,
                  category=category,
                  source=self.name,
                  requires_confirmation=requires_confirmation,
                  metadata=metadata,
                  name_override=name_override,
                  description_override=description_override,
                  schema_override=schema_override,
                  hints=ToolHints(
                      read_only=read_only,
                      destructive=destructive,
                      idempotent=idempotent,
                      open_world=open_world,
                  ),
              )
      

      __aenter__ async

      __aenter__() -> Self
      

      Async context entry if required.

      Source code in src/llmling_agent/resource_providers/base.py
      41
      42
      43
      async def __aenter__(self) -> Self:
          """Async context entry if required."""
          return self
      

      __aexit__ async

      __aexit__(
          exc_type: type[BaseException] | None,
          exc_val: BaseException | None,
          exc_tb: TracebackType | None,
      ) -> None
      

      Async context cleanup if required.

      Source code in src/llmling_agent/resource_providers/base.py
      45
      46
      47
      48
      49
      50
      51
      async def __aexit__(
          self,
          exc_type: type[BaseException] | None,
          exc_val: BaseException | None,
          exc_tb: TracebackType | None,
      ) -> None:
          """Async context cleanup if required."""
      

      __init__

      __init__(name: str, owner: str | None = None) -> None
      

      Initialize the resource provider.

      Source code in src/llmling_agent/resource_providers/base.py
      35
      36
      37
      38
      39
      def __init__(self, name: str, owner: str | None = None) -> None:
          """Initialize the resource provider."""
          self.name = name
          self.owner = owner
          self.log = logger.bind(name=self.name, owner=self.owner)
      

      create_tool

      create_tool(
          fn: Callable[..., Any],
          read_only: bool | None = None,
          destructive: bool | None = None,
          idempotent: bool | None = None,
          open_world: bool | None = None,
          requires_confirmation: bool = False,
          metadata: dict[str, Any] | None = None,
          category: ToolKind | None = None,
          name_override: str | None = None,
          description_override: str | None = None,
          schema_override: OpenAIFunctionDefinition | None = None,
      ) -> Tool
      

      Create a tool from a function.

      Parameters:

      Name Type Description Default
      fn Callable[..., Any]

      Function to create a tool from

      required
      read_only bool | None

      Whether the tool is read-only

      None
      destructive bool | None

      Whether the tool is destructive

      None
      idempotent bool | None

      Whether the tool is idempotent

      None
      open_world bool | None

      Whether the tool is open-world

      None
      requires_confirmation bool

      Whether the tool requires confirmation

      False
      metadata dict[str, Any] | None

      Metadata for the tool

      None
      category ToolKind | None

      Category of the tool

      None
      name_override str | None

      Override the name of the tool

      None
      description_override str | None

      Override the description of the tool

      None
      schema_override OpenAIFunctionDefinition | None

      Override the schema of the tool

      None

      Returns:

      Type Description
      Tool

      Tool created from the function

      Source code in src/llmling_agent/resource_providers/base.py
      125
      126
      127
      128
      129
      130
      131
      132
      133
      134
      135
      136
      137
      138
      139
      140
      141
      142
      143
      144
      145
      146
      147
      148
      149
      150
      151
      152
      153
      154
      155
      156
      157
      158
      159
      160
      161
      162
      163
      164
      165
      166
      167
      168
      169
      170
      171
      172
      def create_tool(
          self,
          fn: Callable[..., Any],
          read_only: bool | None = None,
          destructive: bool | None = None,
          idempotent: bool | None = None,
          open_world: bool | None = None,
          requires_confirmation: bool = False,
          metadata: dict[str, Any] | None = None,
          category: ToolKind | None = None,
          name_override: str | None = None,
          description_override: str | None = None,
          schema_override: OpenAIFunctionDefinition | None = None,
      ) -> Tool:
          """Create a tool from a function.
      
          Args:
              fn: Function to create a tool from
              read_only: Whether the tool is read-only
              destructive: Whether the tool is destructive
              idempotent: Whether the tool is idempotent
              open_world: Whether the tool is open-world
              requires_confirmation: Whether the tool requires confirmation
              metadata: Metadata for the tool
              category: Category of the tool
              name_override: Override the name of the tool
              description_override: Override the description of the tool
              schema_override: Override the schema of the tool
      
          Returns:
              Tool created from the function
          """
          return Tool.from_callable(
              fn=fn,
              category=category,
              source=self.name,
              requires_confirmation=requires_confirmation,
              metadata=metadata,
              name_override=name_override,
              description_override=description_override,
              schema_override=schema_override,
              hints=ToolHints(
                  read_only=read_only,
                  destructive=destructive,
                  idempotent=idempotent,
                  open_world=open_world,
              ),
          )
      

      get_prompts async

      get_prompts() -> list[BasePrompt]
      

      Get available prompts. Override to provide prompts.

      Source code in src/llmling_agent/resource_providers/base.py
      69
      70
      71
      async def get_prompts(self) -> list[BasePrompt]:
          """Get available prompts. Override to provide prompts."""
          return []
      

      get_request_parts async

      get_request_parts(name: str, arguments: dict[str, str] | None = None) -> list[ModelRequestPart]
      

      Get a prompt formatted with arguments.

      Parameters:

      Name Type Description Default
      name str

      Name of the prompt to format

      required
      arguments dict[str, str] | None

      Optional arguments for prompt formatting

      None

      Returns:

      Type Description
      list[ModelRequestPart]

      Single chat message with merged content

      Raises:

      Type Description
      KeyError

      If prompt not found

      ValueError

      If formatting fails

      Source code in src/llmling_agent/resource_providers/base.py
       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
      121
      122
      123
      async def get_request_parts(
          self, name: str, arguments: dict[str, str] | None = None
      ) -> list[ModelRequestPart]:
          """Get a prompt formatted with arguments.
      
          Args:
              name: Name of the prompt to format
              arguments: Optional arguments for prompt formatting
      
          Returns:
              Single chat message with merged content
      
          Raises:
              KeyError: If prompt not found
              ValueError: If formatting fails
          """
          prompts = await self.get_prompts()
          prompt = next((p for p in prompts if p.name == name), None)
          if not prompt:
              msg = f"Prompt {name!r} not found"
              raise KeyError(msg)
      
          messages = await prompt.format(arguments or {})
          if not messages:
              msg = f"Prompt {name!r} produced no messages"
              raise ValueError(msg)
      
          return [p for prompt_msg in messages for p in prompt_msg.to_pydantic_parts()]
      

      get_resources async

      get_resources() -> list[ResourceInfo]
      

      Get available resources. Override to provide resources.

      Source code in src/llmling_agent/resource_providers/base.py
      73
      74
      75
      async def get_resources(self) -> list[ResourceInfo]:
          """Get available resources. Override to provide resources."""
          return []
      

      get_skill_instructions async

      get_skill_instructions(skill_name: str) -> str
      

      Get full instructions for a specific skill.

      Parameters:

      Name Type Description Default
      skill_name str

      Name of the skill to get instructions for

      required

      Returns:

      Type Description
      str

      The full skill instructions for execution

      Raises:

      Type Description
      KeyError

      If skill not found

      Source code in src/llmling_agent/resource_providers/base.py
      81
      82
      83
      84
      85
      86
      87
      88
      89
      90
      91
      92
      93
      94
      async def get_skill_instructions(self, skill_name: str) -> str:
          """Get full instructions for a specific skill.
      
          Args:
              skill_name: Name of the skill to get instructions for
      
          Returns:
              The full skill instructions for execution
      
          Raises:
              KeyError: If skill not found
          """
          msg = f"Skill {skill_name!r} not found"
          raise KeyError(msg)
      

      get_skills async

      get_skills() -> list[Skill]
      

      Get available skills. Override to provide skills.

      Source code in src/llmling_agent/resource_providers/base.py
      77
      78
      79
      async def get_skills(self) -> list[Skill]:
          """Get available skills. Override to provide skills."""
          return []
      

      get_tool async

      get_tool(tool_name: str) -> Tool
      

      Get specific tool.

      Source code in src/llmling_agent/resource_providers/base.py
      60
      61
      62
      63
      64
      65
      66
      67
      async def get_tool(self, tool_name: str) -> Tool:
          """Get specific tool."""
          tools = await self.get_tools()
          for tool in tools:
              if tool.name == tool_name:
                  return tool
          msg = f"Tool {tool_name!r} not found"
          raise ValueError(msg)
      

      get_tools async

      get_tools() -> list[Tool]
      

      Get available tools. Override to provide tools.

      Source code in src/llmling_agent/resource_providers/base.py
      56
      57
      58
      async def get_tools(self) -> list[Tool]:
          """Get available tools. Override to provide tools."""
          return []