How google/langfun works
Langfun is a PyGlove-powered Python library for composing language-model workflows from prompts, types, and program objects. The principal documented workflow is a user calling lf.query with a prompt, output schema, and model, then receiving a typed result. The graph also preserves documented evaluation, multimodal prompting, model integrations, agent/tool use, code generation, and sandboxed environments. Source evidence is uneven: some subsystem links are documented in the README or SOURCE INDEX, while several capabilities are represented by their tree paths without inferred internal call chains.
Main entry points: querying.py Query workflow · language_model.py Model API · session.py MCP sessions · environment.py Environment runtime
Components 20
Structured prompting
- Query workflow
langfun/core/structured/querying.py - Structured mapping
langfun/core/structured/mapping.py - Output schemas
langfun/core/structured/schema/base.py - Prompt templates
langfun/core/template.py
Models and modalities
- Model API
langfun/core/language_model.py - Model providers
langfun/core/llms - Embedding models
langfun/core/embedding_model.py - Media modalities
langfun/core/modalities
Agents and tools
- Agent actions
langfun/core/agentic/action.py - MCP clients
langfun/core/mcp/client.py - MCP sessions
langfun/core/mcp/session.py - MCP tools
langfun/core/mcp/tool.py
Evaluation
- Evaluation framework
langfun/core/eval
Code and environments
- Python code workflows
langfun/core/coding/python - Environment runtime
langfun/env/environment.py - Sandbox services
langfun/env/base_sandbox_service.py - Environment interfaces
langfun/env/interface.py
Other components
- Library user
- LLM services
- MCP servers
Connections 19
- Library user → Query workflow: calls
- Query workflow → Structured mapping: uses mapping
langfun/core/structured/querying.py - Query workflow → Output schemas: uses schema
langfun/core/structured/querying.py - Query workflow → Model API: requests completion
- Model API → LLM services: sends requests
- Model providers → LLM services: connects
- Model API → Media modalities: supports media
- Embedding models → Model API: shares model base
langfun/core/embedding_model.py - Library user → Agent actions: creates actions
- MCP clients → MCP sessions: creates sessions
langfun/core/mcp/client.py - MCP sessions → MCP tools: dispatches calls
langfun/core/mcp/session.py - MCP sessions → MCP servers: communicates
- MCP tools → MCP servers: calls tools
langfun/core/mcp/tool.py - Library user → Evaluation framework: runs evaluations
- Library user → Python code workflows: generates code
- Library user → Environment runtime: uses environments
- Environment runtime → Environment interfaces: implements lifecycle
langfun/env/environment.py - Environment runtime → Sandbox services: starts services
- Sandbox services → Environment interfaces: implements service
langfun/env/base_sandbox_service.py