langgoap.GoalInterpreter#
- class GoalInterpreter(llm, actions, system_prompt=None, structured_output_kwargs=None)[source]#
Converts natural language requests into GoalSpec objects via LLM.
Uses
BaseChatModel.with_structured_output()to extract structured goals from free-text requests. Provider-agnostic: any chat model that supports structured output works.- Parameters:
llm (BaseChatModel) – A LangChain chat model (e.g.
ChatOpenAI,ChatAnthropic).actions (list[ActionSpec]) – Available GOAP actions (used to build the prompt catalog).
system_prompt (str | None) – Custom system prompt template. Must contain
{action_catalog}and{world_state}placeholders. Defaults toDEFAULT_SYSTEM_PROMPT.structured_output_kwargs (dict[str, Any] | None) – Optional keyword arguments forwarded to
llm.with_structured_output(). Use this for provider-specific options, e.g.{"method": "function_calling"}for OpenAI whenconditionsmust remain an open dict (OpenAI strict JSON-schema mode requiresadditionalProperties: falseon all objects, which is incompatible with a free-form conditions mapping). WhenNone(the default), auto-detects OpenAI models and applies{"method": "function_calling"}automatically.
- __init__(llm, actions, system_prompt=None, structured_output_kwargs=None)[source]#
- Parameters:
llm (BaseChatModel)
actions (list[ActionSpec])
system_prompt (str | None)
structured_output_kwargs (dict[str, Any] | None)
- Return type:
None
Methods
__init__(llm, actions[, system_prompt, ...])ainterpret(request[, world_state])Async variant of
interpret().ainterpret_raw(request[, world_state])Async variant of
interpret_raw().build_messages(request, world_state)interpret(request[, world_state])Interpret a natural language request and return a GoalSpec.
interpret_raw(request[, world_state])Interpret a request and return the raw InterpretedGoal.