Skip to content

context

Class info

Classes

Name Children Inherits
AgentContext
llmling_agent.agent.context
Runtime context for agent execution.
    ConversionManager
    llmling_agent.prompts.conversion_manager
    Manages document conversion using configured providers.
      NodeContext
      llmling_agent.messaging.context
      NodeContext(*, node_name: 'str', pool: 'AgentPool | None' \= None, config: 'NodeConfig', definition: 'AgentsManifest', current_prompt: 'str | None' \= None, in_async_context: 'bool' \= False, input_provider: 'InputProvider | None' \= None)

      🛈 DocStrings

      Runtime context models for Agents.

      AgentContext dataclass

      Bases: NodeContext[TDeps]

      Runtime context for agent execution.

      Generically typed with AgentContext[Type of Dependencies]

      Source code in src/llmling_agent/agent/context.py
       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
      @dataclass(kw_only=True)
      class AgentContext[TDeps](NodeContext[TDeps]):
          """Runtime context for agent execution.
      
          Generically typed with AgentContext[Type of Dependencies]
          """
      
          capabilities: Capabilities
          """Current agent's capabilities."""
      
          config: AgentConfig
          """Current agent's specific configuration."""
      
          model_settings: dict[str, Any] = field(default_factory=dict)
          """Model-specific settings."""
      
          data: TDeps | None = None
          """Custom context data."""
      
          runtime: RuntimeConfig | None = None
          """Reference to the runtime configuration."""
      
          @classmethod
          def create_default(
              cls,
              name: str,
              capabilities: Capabilities | None = None,
              deps: TDeps | None = None,
              pool: AgentPool | None = None,
              input_provider: InputProvider | None = None,
          ) -> AgentContext[TDeps]:
              """Create a default agent context with minimal privileges.
      
              Args:
                  name: Name of the agent
                  capabilities: Optional custom capabilities (defaults to minimal access)
                  deps: Optional dependencies for the agent
                  pool: Optional pool the agent is part of
                  input_provider: Optional input provider for the agent
              """
              from llmling_agent.config.capabilities import Capabilities
              from llmling_agent.models import AgentConfig, AgentsManifest
      
              caps = capabilities or Capabilities()
              defn = AgentsManifest()
              cfg = AgentConfig(name=name)
              return cls(
                  input_provider=input_provider,
                  node_name=name,
                  capabilities=caps,
                  definition=defn,
                  config=cfg,
                  data=deps,
                  pool=pool,
              )
      
          @cached_property
          def converter(self) -> ConversionManager:
              """Get conversion manager from global config."""
              return ConversionManager(self.definition.conversion)
      
          # TODO: perhaps add agent directly to context?
          @property
          def agent(self) -> AnyAgent[TDeps, Any]:
              """Get the agent instance from the pool."""
              assert self.pool, "No agent pool available"
              assert self.node_name, "No agent name available"
              return self.pool.agents[self.node_name]
      
          async def handle_confirmation(
              self,
              tool: ToolInfo,
              args: dict[str, Any],
          ) -> ConfirmationResult:
              """Handle tool execution confirmation.
      
              Returns True if:
              - No confirmation handler is set
              - Handler confirms the execution
              """
              provider = self.get_input_provider()
              mode = self.config.requires_tool_confirmation
              if (mode == "per_tool" and not tool.requires_confirmation) or mode == "never":
                  return "allow"
              history = self.agent.conversation.get_history() if self.pool else []
              return await provider.get_tool_confirmation(self, tool, args, history)
      

      agent property

      agent: AnyAgent[TDeps, Any]
      

      Get the agent instance from the pool.

      capabilities instance-attribute

      capabilities: Capabilities
      

      Current agent's capabilities.

      config instance-attribute

      config: AgentConfig
      

      Current agent's specific configuration.

      converter cached property

      converter: ConversionManager
      

      Get conversion manager from global config.

      data class-attribute instance-attribute

      data: TDeps | None = None
      

      Custom context data.

      model_settings class-attribute instance-attribute

      model_settings: dict[str, Any] = field(default_factory=dict)
      

      Model-specific settings.

      runtime class-attribute instance-attribute

      runtime: RuntimeConfig | None = None
      

      Reference to the runtime configuration.

      create_default classmethod

      create_default(
          name: str,
          capabilities: Capabilities | None = None,
          deps: TDeps | None = None,
          pool: AgentPool | None = None,
          input_provider: InputProvider | None = None,
      ) -> AgentContext[TDeps]
      

      Create a default agent context with minimal privileges.

      Parameters:

      Name Type Description Default
      name str

      Name of the agent

      required
      capabilities Capabilities | None

      Optional custom capabilities (defaults to minimal access)

      None
      deps TDeps | None

      Optional dependencies for the agent

      None
      pool AgentPool | None

      Optional pool the agent is part of

      None
      input_provider InputProvider | None

      Optional input provider for the agent

      None
      Source code in src/llmling_agent/agent/context.py
      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
      @classmethod
      def create_default(
          cls,
          name: str,
          capabilities: Capabilities | None = None,
          deps: TDeps | None = None,
          pool: AgentPool | None = None,
          input_provider: InputProvider | None = None,
      ) -> AgentContext[TDeps]:
          """Create a default agent context with minimal privileges.
      
          Args:
              name: Name of the agent
              capabilities: Optional custom capabilities (defaults to minimal access)
              deps: Optional dependencies for the agent
              pool: Optional pool the agent is part of
              input_provider: Optional input provider for the agent
          """
          from llmling_agent.config.capabilities import Capabilities
          from llmling_agent.models import AgentConfig, AgentsManifest
      
          caps = capabilities or Capabilities()
          defn = AgentsManifest()
          cfg = AgentConfig(name=name)
          return cls(
              input_provider=input_provider,
              node_name=name,
              capabilities=caps,
              definition=defn,
              config=cfg,
              data=deps,
              pool=pool,
          )
      

      handle_confirmation async

      handle_confirmation(tool: ToolInfo, args: dict[str, Any]) -> ConfirmationResult
      

      Handle tool execution confirmation.

      Returns True if: - No confirmation handler is set - Handler confirms the execution

      Source code in src/llmling_agent/agent/context.py
      100
      101
      102
      103
      104
      105
      106
      107
      108
      109
      110
      111
      112
      113
      114
      115
      116
      async def handle_confirmation(
          self,
          tool: ToolInfo,
          args: dict[str, Any],
      ) -> ConfirmationResult:
          """Handle tool execution confirmation.
      
          Returns True if:
          - No confirmation handler is set
          - Handler confirms the execution
          """
          provider = self.get_input_provider()
          mode = self.config.requires_tool_confirmation
          if (mode == "per_tool" and not tool.requires_confirmation) or mode == "never":
              return "allow"
          history = self.agent.conversation.get_history() if self.pool else []
          return await provider.get_tool_confirmation(self, tool, args, history)