langgoap.PromptConditionResolver

langgoap.PromptConditionResolver#

class PromptConditionResolver(llm, *, prompt_template=None, timeout_s=30.0)[source]#

Resolve a condition key by querying an LLM.

Uses LangChain’s BaseChatModel.with_structured_output to obtain a structured TRUE / FALSE / UNKNOWN answer from the model. The model is given the condition key and the current world-state as context.

Parameters:
  • llm (Any) – Any LangChain BaseChatModel (ChatOpenAI, ChatAnthropic, …).

  • prompt_template (str | None) – Optional f-string template. Available variables: {key} — the condition key being resolved; {world_state} — the current world state dict as a string. Defaults to a concise diagnostic prompt.

  • timeout_s (float) – Per-call timeout in seconds (default 30).

Example:

from langchain_openai import ChatOpenAI
from langgoap.conditions import PromptConditionResolver

resolver = PromptConditionResolver(ChatOpenAI(model="gpt-4o-mini"))
status = resolver.resolve("has_permission", {"user_role": "admin"})
__init__(llm, *, prompt_template=None, timeout_s=30.0)[source]#
Parameters:
  • llm (Any)

  • prompt_template (str | None)

  • timeout_s (float)

Return type:

None

Methods

__init__(llm, *[, prompt_template, timeout_s])

aresolve(key, world_state)

Async LLM query.

resolve(key, world_state)

Synchronously query the LLM and return a ConditionStatus.

Attributes

name