Core
Look up coco_core messages, tools and injected arguments, runnables and prompts, and the in-memory tracing classes.
Look up coco_core, from the trustcoco-core distribution.
Messages
From coco_core.messages, also importable from coco.messages:
| Name | Description |
|---|---|
HumanMessage(content, **kwargs) | A message from a person. Content is a string or a list of content blocks. |
AIMessage(content, *, tool_calls=..., usage_metadata=..., **kwargs) | A message from the model, with its tool_calls and usage_metadata. |
AIMessageChunk | A streamed piece of an AIMessage. Chunks add together with +. |
SystemMessage(content, **kwargs) | A system instruction. |
ToolMessage(content, *, tool_call_id, name=..., status="success" | "error", artifact=...) | A tool's result, linked to the model's tool call by tool_call_id. |
RemoveMessage(id) | Tells the add_messages reducer to delete a message, or all of them with REMOVE_ALL_MESSAGES. |
trim_messages(messages, *, max_tokens, token_counter, strategy="last", ...) | Trims messages to a token budget and keeps the order valid. |
Content blocks include TextContentBlock, ReasoningContentBlock, ImageContentBlock, AudioContentBlock, VideoContentBlock, FileContentBlock, ToolCall and ServerToolCall.
Tools
From coco_core.tools, also importable from coco.tools:
from coco_core.tools import tool, BaseTool, StructuredTool, ToolException, InjectedToolArg, InjectedToolCallId
from pydantic import BaseModel, Field
class SearchInput(BaseModel):
query: str = Field(description="Search query string")
limit: int = Field(default=5, description="Maximum results to return")
@tool("search_knowledge_base", args_schema=SearchInput, return_direct=False)
def search_kb(query: str, limit: int = 5) -> str:
"""Search the internal knowledge base for relevant articles."""
return f"Found {limit} results for '{query}'"@tool infers the argument schema from the function's signature and docstring, or takes args_schema. Annotate a parameter with InjectedToolArg, InjectedToolCallId, InjectedState, InjectedStore or ToolRuntime to fill it at run time, hidden from the model.
Runnables and prompts
Every runnable, from prompts and models to tools and compiled graphs, has invoke, stream, batch and astream_events, and their async versions.
from coco_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from coco_core.output_parsers import StrOutputParser
from coco_openai import ChatOpenAI
model = ChatOpenAI(model="gpt-4o", temperature=0)
prompt = ChatPromptTemplate.from_messages(
[
("system", "You are a technical writer specializing in {domain}."),
MessagesPlaceholder("history", optional=True),
("human", "{question}"),
]
)
chain = prompt | model | StrOutputParser()
answer = chain.invoke({"domain": "distributed systems", "question": "Explain consensus."})| Name | Description |
|---|---|
RunnableSequence | Runs steps in order. a | b makes one. |
RunnableParallel | Runs steps on the same input at once. |
RunnableLambda | Wraps a function as a runnable. |
RunnablePassthrough | Passes the input through, optionally adding keys. |
RunnableBranch | Picks a step by condition. |
RunnableWithFallbacks | Tries other runnables when one fails. |
RunnableConfig | Carries configurable (such as thread_id), tags, metadata, callbacks, max_concurrency and recursion_limit. |
Tracing
| Name | Import | Description |
|---|---|---|
CocoTracer | coco_core.tracers.coco | Records runs in memory and keeps the root run on .latest_run. Never makes network calls. |
Run, RunTree | coco_core.tracers._context | A trace span: id, name, run_type, start_time, end_time, inputs, outputs, events, error, tags, extra. |
tracing_context | coco_core.tracers._context | with tracing_context(enabled=True, project_name="...", tags=[...], metadata={...}): scopes tracing settings. |
TracePolicy, omit_payload | coco.agents.middleware | Scrub payloads from middleware spans, globally with configure_trace_policy(...). |
See Tracing.
Graphs and checkpointers
Look up StateGraph and CompiledStateGraph methods, the control flow types interrupt, Command, Send and the policies, the prebuilt nodes, and the checkpointers.
Model providers
Look up the classes and environment variables of coco_openai and coco_anthropic, and how each handles retries, timeouts and rate limits.