Agents API Reference¶
cs_copilot.agents
¶
Factories and team builders for ChemSpace Copilot agents.
The registry contains nine agent types. Seven are members of the production
team: ChEMBL retrieval, GTM, chemoinformatics, reporting, molecular design,
peptide design, and retrosynthesis. robustness_evaluation is a separate
evaluation agent, while single_agent is the flat baseline used by
architecture-ablation tests.
Use :func:create_agent to construct one registered type,
:func:get_cs_copilot_agent_team for the production team, or
:func:get_cs_copilot_single_agent for the controlled baseline.
Exports are resolved lazily so that importing a lightweight submodule such as
:mod:cs_copilot.agents.instructions (used verbatim by the MCP prompt
registry) does not construct the Agno team, factory, or registry modules.
AgentConfig
dataclass
¶
Configuration for creating an agent.
Source code in src/cs_copilot/agents/factories.py
validate()
¶
Validate the agent configuration.
Source code in src/cs_copilot/agents/factories.py
AgentCreationError
¶
BaseAgentFactory
¶
Bases: ABC
Base class for creating agents with common configuration and error handling.
Source code in src/cs_copilot/agents/factories.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
get_agent_config()
abstractmethod
¶
create_agent(model, markdown=True, debug_mode=False, enable_mlflow_tracking=True, **kwargs)
¶
Create an agent with error handling and validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
Model to use for the agent |
required |
markdown
|
bool
|
Whether to enable markdown formatting |
True
|
debug_mode
|
bool
|
Whether to enable debug mode |
False
|
enable_mlflow_tracking
|
bool
|
Whether to enable MLflow tracking for this agent |
True
|
**kwargs
|
Any
|
Additional keyword arguments for agent creation |
{}
|
Returns:
| Type | Description |
|---|---|
Agent
|
Created agent instance |
Source code in src/cs_copilot/agents/factories.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
create_agent(agent_type, model, **kwargs)
¶
Create an agent by type using the global registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_type
|
str
|
The type of agent to create |
required |
model
|
Model
|
The language model to use |
required |
**kwargs
|
Any
|
Additional arguments passed to the agent factory |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Agent |
Agent
|
The created agent instance |
Raises:
| Type | Description |
|---|---|
ValueError
|
If agent_type is not registered |
AgentCreationError
|
If agent creation fails |
Source code in src/cs_copilot/agents/registry.py
get_registry()
¶
list_available_agent_types()
¶
get_cs_copilot_single_agent(model, *, markdown=True, debug_mode=False, enable_mlflow_tracking=True)
¶
Create the single flat agent (all toolkits, no team, no routing).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
Agno Model instance — pass the SAME instance used for the team so the ablation holds the model constant. |
required |
markdown
|
bool
|
Format output in markdown (matches team members). |
True
|
debug_mode
|
bool
|
Enable debug logs. |
False
|
enable_mlflow_tracking
|
bool
|
Wrap |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
Agent |
Agent
|
The configured single-agent baseline. Exposes |
Agent
|
|
|
Agent
|
either arm through one interface. |
Source code in src/cs_copilot/agents/single_agent.py
get_cs_copilot_agent_team(model, *, markdown=True, debug_mode=False, show_members_responses=True, enable_memory=True, db_file=None, enable_mlflow_tracking=True, run_context=None, execution_mode=None)
¶
Create a coordinated team of cs_copilot agents using Agno.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
Agno Model instance used for team coordination and member agents |
required |
markdown
|
bool
|
Format output in markdown |
True
|
debug_mode
|
bool
|
Enable debug logs |
False
|
show_members_responses
|
bool
|
Print member responses during coordination |
True
|
enable_memory
|
bool
|
Enable persistent session history (default: True). Cross-session user/agentic memories stay disabled to prevent state leakage. |
True
|
db_file
|
str
|
Custom database file path. If not provided, uses CS_COPILOT_MEMORY_DB. Use unique paths for session isolation in testing. |
None
|
enable_mlflow_tracking
|
bool
|
Enable MLflow tracking for agents (default: True). Set to False to disable tracking. |
True
|
run_context
|
Any
|
Optional v2 workflow |
None
|
execution_mode
|
ExecutionMode | str | None
|
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Team |
Team
|
Configured Cs_copilot team |
Raises:
| Type | Description |
|---|---|
AgentCreationError
|
If one or more agents fail to initialize |
Source code in src/cs_copilot/agents/teams.py
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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
get_last_agent_reply(agent)
¶
Extract the content of the last message from an agent's session.
agno_compat
¶
Compatibility fixes for the pinned Agno release.
Agno 2.1.9's Model.arun_function_call leaves its result unassigned
when a tool's pre-hook raises an AgentRunException (RetryAgentRun /
StopAgentRun), so the async team path crashes with UnboundLocalError
instead of turning the exception into a retry request for the model, as the
synchronous run_function_call does. The structured-handoff guard rejects
malformed delegations exactly that way, so without this fix any rejected
delegation in an async chat (Chainlit, the CLI) aborts the whole turn.
:func:patch_async_function_call_retry installs the upstream method with the
single missing initialization. It only applies to the pinned version and is
idempotent.
patch_async_function_call_retry()
¶
Make async tool pre-hook retries behave like the synchronous path.
Returns whether the patch is active.
Source code in src/cs_copilot/agents/agno_compat.py
patch_tool_result_coercion()
¶
Stop Agno truth-testing a tool result it cannot truth-test.
Agno 2.1.9 renders every tool result with
str(result) if result else "" (agno/models/base.py). A pandas
DataFrame raises ValueError there, aborting a run the agent had already
largely completed, and a NumPy array raises the same way.
Patching :meth:FunctionCall.execute covers every caller -- the team path,
the flat single-agent baseline, and tool calls a member makes while a
delegation is in flight -- because that is where Agno collects the value.
The execution kernel has already seen the raw value by then, so artifact
registration is unaffected.
Returns whether the patch is active.
Source code in src/cs_copilot/agents/agno_compat.py
patch_literal_enum_schema()
¶
Advertise Literal parameters to the model as string enums.
Agno 2.1.9's schema builder has no branch for :data:typing.Literal, so
every such parameter falls through to the generic object case and reaches
the model as {"type": "object", "properties": {}} -- no values, no
default. Pydantic then rejects the call at runtime with "Input should be
'x' or 'y'", penalising the model for a constraint it was never shown, and
a model that obeys the advertised schema sends a dict and fails the same
way.
Returns whether the patch is active.
Source code in src/cs_copilot/agents/agno_compat.py
config
¶
Configuration module for cs_copilot agents.
Agent personas and behavioral instructions live in descriptions.py and
instructions.py respectively.
context
¶
Explicit context budgets for bounded, auditable agent handoffs.
ContextBudget
dataclass
¶
Per-component token allocation for a specialist invocation.
Source code in src/cs_copilot/agents/context.py
BoundedContext
dataclass
¶
Prompt sections and their measured size after explicit truncation.
Source code in src/cs_copilot/agents/context.py
ContextBuilder
¶
Build bounded receiver context without forwarding a full conversation.
Source code in src/cs_copilot/agents/context.py
build(handoff, *, system_policy, procedure, run_summary, tool_schemas, recent_messages=())
¶
Fit each component independently and report every truncation.
Source code in src/cs_copilot/agents/context.py
contracts
¶
Typed contracts for specialist roles and multi-agent handoffs.
These contracts deliberately carry task facts and artifact references only. Conversation histories, scratchpads, private reasoning, and chain-of-thought are not valid handoff fields.
ExecutionBudget
dataclass
¶
Bounded resources a receiving role may spend on one task.
Source code in src/cs_copilot/agents/contracts.py
RolePolicy
dataclass
¶
Allowlist for one in-process Agno specialist role.
Source code in src/cs_copilot/agents/contracts.py
validate_role_tools(policy, tools)
¶
Reject a factory configuration that grants tools outside its role policy.
Source code in src/cs_copilot/agents/contracts.py
record_handoff(runtime, envelope)
¶
Record a handoff through a v2 RunContext when one is available.
Source code in src/cs_copilot/agents/contracts.py
delegation
¶
Agno coordinator guard for structured, bounded specialist delegation.
DelegationLimits
dataclass
¶
Hard limits applied to one coordinator run.
Source code in src/cs_copilot/agents/delegation.py
StructuredDelegationGuard
¶
Validate and canonicalize Agno's generated delegation tool calls.
The guard is installed as the generated delegation Function.pre_hook.
Agno invokes synchronous pre-hooks in both its sync and async execution
paths, so validation is identical without wrapping unrelated team tools.
Source code in src/cs_copilot/agents/delegation.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | |
pre_hook(*, team=None, session_state=None, fc=None)
¶
Agno Function.pre_hook entry point.
Source code in src/cs_copilot/agents/delegation.py
hook_for_run(coordinator_run_id)
¶
Bind counters to Agno's immutable run ID instead of mutable session state.
Source code in src/cs_copilot/agents/delegation.py
StructuredHandoffTeam
¶
Bases: Team
Team variant that keeps implicit coordinator context out of member prompts.
Agno 2.1.9 has one add_history_to_context flag for both the coordinator
and delegated members. The only narrow seam that can preserve coordinator
history while disabling member history is the generated delegate-function
builder. This override changes only those member-call flags.
Source code in src/cs_copilot/agents/delegation.py
descriptions
¶
Agent persona descriptions for cs_copilot.
These strings answer who each agent is — the identity/role that Agno injects
into the system message via Agent(description=...). They are deliberately
kept separate from the behavioral rules in instructions.py (Agno's
instructions=) and from the multi-tool procedures in the skill/workflow
catalogs. Change a persona here; change how it behaves in instructions.py;
change what it does step by step in skills/ or workflow_catalog/.
execution_binding
¶
Route the in-process Agno team's toolkit calls through the execution kernel.
:func:attach_execution wraps every toolkit function of a team (coordinator
toolkits and every member's toolkits and bare-function tools) with a
signature-preserving entrypoint. Each call is then recorded in the chat's
durable workflow run like an MCP tool call: same event protocol, same tool
identity (via :mod:cs_copilot.agents.execution_contracts), same artifact
registration.
The mode comes from CS_COPILOT_AGNO_EXECUTION (default enforce):
off: no wrapping; behaviour and storage are exactly as before.observe: calls run unchanged; events, artifact registration, and an audit of what enforcement would rewrite or deny are recorded (:func:cs_copilot.execution.runner.observe_sync).enforce(default): the full kernel (:func:cs_copilot.execution.runner.execute_sync): output paths are rewritten into the chat's run, writes are confined and create-only, declared file inputs must be registered artifacts, every file a call writes is registered, and a call's files are rolled back if it fails. Denials reach the model as tool errors.
Agno hooks are deliberately not used: Team.tool_hooks would also wrap the
async-generator delegation tool, hooks cannot rewrite arguments, and they do
not know which toolkit a call belongs to.
ExecutionBinding
dataclass
¶
Per-team routing state: the chat's run, the mode, and task attribution.
Source code in src/cs_copilot/agents/execution_binding.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
wait_idle(timeout=None)
¶
Block until no bound call is running (used before cancelling a run).
Source code in src/cs_copilot/agents/execution_binding.py
invoke(function, owner, args, kwargs, *, context=None)
¶
Run one Agno tool call, recording it through the kernel when enabled.
kwargs are what function receives. context holds Agno's
agent / team / session_state for functions that do not
declare them; they inform the recording but are never passed on.
Source code in src/cs_copilot/agents/execution_binding.py
execution_mode_from_env(value=None)
¶
Resolve an execution mode from value or CS_COPILOT_AGNO_EXECUTION.
Source code in src/cs_copilot/agents/execution_binding.py
attach_execution(team, *, run_context, mode=None)
¶
Route team's tool calls through the kernel for run_context.
Idempotent: re-attaching updates the run and mode of the existing binding. Must run before the team's first run, because Agno processes tool entrypoints when it first builds the model's tool list.
Source code in src/cs_copilot/agents/execution_binding.py
execution_contracts
¶
Map in-process Agno tool functions to execution-kernel contracts.
Every MCP tool spec names the in-process implementations of its operation in
ToolSpec.agno_bindings (module:Class.method or module:function).
This module indexes those bindings by the function object they resolve to, so
an Agno toolkit call is recorded under the same tool identity and execution
contract as its MCP twin. Functions without an MCP twin get a conservative
synthesized contract named agno.<Owner>.<function>.
The MCP tool catalog (cs_copilot.mcp.tools_registry) is imported lazily;
the MCP server module and the mcp SDK never are.
function_key(function)
¶
Identify a callable by its defining module and qualified name.
Source code in src/cs_copilot/agents/execution_contracts.py
binding_target(binding)
¶
Import the function a module:Class.method / module:function names.
Source code in src/cs_copilot/agents/execution_contracts.py
contract_index()
¶
Return (building once) the function-to-contract index of the MCP catalog.
Source code in src/cs_copilot/agents/execution_contracts.py
resolve_contract(function, *, owner=None)
¶
Return (contract, source) for an Agno tool function.
source is "spec" for a function bound to an MCP tool spec and
"default" for a synthesized contract. owner is the toolkit instance
(or None for a bare function tool).
Source code in src/cs_copilot/agents/execution_contracts.py
reset_contract_index()
¶
factories
¶
Agent factory classes for creating specialized cs_copilot agents. Contains the base factory class and all specialized factory implementations.
AgentConfig
dataclass
¶
Configuration for creating an agent.
Source code in src/cs_copilot/agents/factories.py
validate()
¶
Validate the agent configuration.
Source code in src/cs_copilot/agents/factories.py
AgentCreationError
¶
BaseAgentFactory
¶
Bases: ABC
Base class for creating agents with common configuration and error handling.
Source code in src/cs_copilot/agents/factories.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
get_agent_config()
abstractmethod
¶
create_agent(model, markdown=True, debug_mode=False, enable_mlflow_tracking=True, **kwargs)
¶
Create an agent with error handling and validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
Model to use for the agent |
required |
markdown
|
bool
|
Whether to enable markdown formatting |
True
|
debug_mode
|
bool
|
Whether to enable debug mode |
False
|
enable_mlflow_tracking
|
bool
|
Whether to enable MLflow tracking for this agent |
True
|
**kwargs
|
Any
|
Additional keyword arguments for agent creation |
{}
|
Returns:
| Type | Description |
|---|---|
Agent
|
Created agent instance |
Source code in src/cs_copilot/agents/factories.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
ChEMBLDownloaderFactory
¶
Bases: BaseAgentFactory
Factory for creating ChemBL downloader agents.
Source code in src/cs_copilot/agents/factories.py
ChemoinformaticianFactory
¶
Bases: BaseAgentFactory
Factory for creating comprehensive chemoinformatics analysis agents.
This agent is a versatile chemoinformatician capable of: - Chemotype Analysis: Scaffold extraction, chemotype profiling, structural diversity - Clustering: Molecular clustering using various methods (k-means, hierarchical, DBSCAN) - SAR Analysis: Structure-Activity Relationship analysis, activity cliffs, matched molecular pairs - Similarity Analysis: Molecular similarity, diversity metrics, nearest neighbor searches
GTM-Integrated Design: - Primary use case: Downstream analysis after GTM agents (nodes as clusters) - Also works with ANY data source: t-SNE clusters, user CSVs, ChEMBL families - Standardized input: DataFrame with 'smiles' + optional 'cluster_id' + optional 'activity' - Produces structured data output (DataFrames, dicts) - NO report generation - Report generation handled by separate ReportGeneratorAgent
Tools: - ChemicalSimilarityToolkit: Fingerprints, similarity metrics, scaffold extraction - PointerPandasTools: DataFrame operations with S3 support - GTMToolkit: Access to GTM data (source_mols, node projections)
Source code in src/cs_copilot/agents/factories.py
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
MolecularDesignerFactory
¶
Bases: BaseAgentFactory
Factory for creating small-molecule design agents.
Supports two modes: - Engine-driven design: Use autoencoder or LLM engines behind a common facade - Standalone autoencoder: Encode/decode SMILES, sample latent space, interpolate, explore neighborhoods - GTM-guided: Combine GTM maps with generative engines for targeted molecular design from specific map regions (by density, activity, or coordinates)
Enhanced with GTM cache awareness to avoid redundant GTM loading when working with GTM Agent in the same session.
Source code in src/cs_copilot/agents/factories.py
GTMAgentFactory
¶
Bases: BaseAgentFactory
Factory for creating unified GTM agents (consolidates optimization, loading, density, activity, projection).
This factory creates a single agent that handles all GTM-related operations via mode-based dispatch: - optimize: Build and optimize new GTM maps - load: Load existing GTM models from S3/local/HuggingFace - density: Analyze compound distributions and neighborhood preservation - activity: Create activity landscapes for SAR analysis - project: Project external datasets onto existing GTM maps
Features smart caching to avoid redundant GTM loading across operations.
Source code in src/cs_copilot/agents/factories.py
ReportGeneratorFactory
¶
Bases: BaseAgentFactory
Factory for creating report generation agents.
This agent handles ALL report generation and visualization across different analysis types: - Chemotype analysis reports - GTM density reports - GTM activity/SAR reports - Molecular designer generation reports - Combined/custom reports
Separation of Concerns: Analysis agents produce structured data, Report Generator handles presentation.
This architecture enables: - Consistent formatting across all report types - Reusable visualization patterns - Easy updates to report styles (change in one place) - Clean separation: data processing vs visualization/formatting
Source code in src/cs_copilot/agents/factories.py
RobustnessEvaluationFactory
¶
Bases: BaseAgentFactory
Factory for creating robustness test evaluation agents.
Source code in src/cs_copilot/agents/factories.py
SynPlannerFactory
¶
Bases: BaseAgentFactory
Factory for creating retrosynthetic planning agents powered by SynPlanner.
This agent wraps the official SynPlanner package to perform retrosynthetic analysis on target molecules. It accepts SMILES strings or molecule names, resolves them to canonical SMILES (via PubChem / RDKit), runs the MCTS-based retrosynthesis search, and returns structured route descriptions with optional SVG/PNG visualizations.
Source code in src/cs_copilot/agents/factories.py
PeptideDesignerFactory
¶
Bases: BaseAgentFactory
Factory for creating peptide design agents.
This agent exposes a Peptide Designer facade over multiple peptide design engines. The default WAE engine encodes, decodes, samples, and interpolates amino acid sequences; the LLM engine proposes sequence candidates from natural-language objectives. The WAE model can generate any peptides; activity landscape data comes from DBAASP (antimicrobial peptides specifically).
Key capabilities: - Encoding: Convert peptide sequences to 100-dimensional latent vectors - Decoding: Generate peptide sequences from latent vectors - Sampling: Generate novel peptides from Gaussian prior - Interpolation: Smooth transitions between peptides in latent space - Neighborhood exploration: Generate peptide analogs - GTM integration: Train GTMs on latent space, create activity landscapes - Activity landscapes: Use DBAASP data (specific to antimicrobial peptides)
Input format: Space-separated single-letter amino acid codes Example: "M L L L L L A L A L L A L L L A L L L"
Source code in src/cs_copilot/agents/factories.py
SingleAgentFactory
¶
Bases: BaseAgentFactory
Factory for the single-agent baseline used in the multi-agent ablation.
One flat Agno Agent that holds the UNION of the seven team specialists'
toolkits (ChEMBL, GTM, chemoinformatics, molecular + peptide design,
retrosynthesis, reporting) with no coordinator, no routing, and no
per-specialist context isolation. It is deliberately NOT added to the runtime
team (teams.py stays 7 members); it is constructed separately for the
robustness comparison so the only variable vs the team is the agentic
structure (same model, same tools, same tasks).
Agno registers toolkit methods by name and keeps the first-registered on a
clash. The peptide toolkit is therefore registered under its MCP-style
peptide_* namespace in this flat context. Specialist agents retain their
native unprefixed names because their tool contexts are already isolated.
Source code in src/cs_copilot/agents/factories.py
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 | |
instructions
¶
Agent behavioral instructions for cs_copilot.
These lists answer how each agent behaves — the rules, policies, and
conventions that Agno injects into the system message via
Agent(instructions=...). They are deliberately kept separate from the
persona identities in descriptions.py (Agno's description=) and from
the mutable multi-tool procedures in the skill/workflow catalogs. Each agent's
instructions point at the catalog and expect the agent to fetch and follow the
procedure there rather than embedding step-by-step tool sequences here.
registry
¶
Agent registry system for managing and creating agents dynamically. Provides the main public API for agent creation.
AgentRegistry
¶
Registry for managing agent factories and configurations.
Source code in src/cs_copilot/agents/registry.py
register(agent_type, factory, aliases=None)
¶
Register an agent factory with optional aliases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_type
|
str
|
Canonical agent type name |
required |
factory
|
BaseAgentFactory
|
Factory instance |
required |
aliases
|
List[str]
|
Optional list of alias names that redirect to this agent |
None
|
Source code in src/cs_copilot/agents/registry.py
create_agent(agent_type, model, **kwargs)
¶
Create an agent by type (supports aliases).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_type
|
str
|
Agent type or alias |
required |
model
|
Model
|
LLM model instance |
required |
**kwargs
|
Any
|
Additional arguments for agent creation |
{}
|
Returns:
| Type | Description |
|---|---|
Agent
|
Agent instance |
Raises:
| Type | Description |
|---|---|
ValueError
|
If agent_type/alias is not registered |
Source code in src/cs_copilot/agents/registry.py
list_agent_types()
¶
auto_register()
¶
Automatically discover and register all available factories.
Source code in src/cs_copilot/agents/registry.py
create_agent(agent_type, model, **kwargs)
¶
Create an agent by type using the global registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_type
|
str
|
The type of agent to create |
required |
model
|
Model
|
The language model to use |
required |
**kwargs
|
Any
|
Additional arguments passed to the agent factory |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Agent |
Agent
|
The created agent instance |
Raises:
| Type | Description |
|---|---|
ValueError
|
If agent_type is not registered |
AgentCreationError
|
If agent creation fails |
Source code in src/cs_copilot/agents/registry.py
list_available_agent_types()
¶
session_runs
¶
One durable v2 workflow run per in-process chat.
Chainlit and the CLI keep conversation history in Agno's SQLite store; the
scientific state of a chat — tool events, registered artifacts, handoffs — is
recorded in one ad-hoc agno-session workflow run per chat. The run is
created lazily before the first message is processed, reused when a chat
resumes, and never completed automatically because a chat can always resume.
ensure_agno_session_run(team, *, session_id, mode=None)
¶
Return the chat's durable run, creating and binding it on first use.
Returns None when the execution mode is off. Idempotent: once a
run is attached to team it is returned as is.
Source code in src/cs_copilot/agents/session_runs.py
restore_team_session_state(team, saved_state)
¶
Restore a persisted chat state into the team's shared dict in place.
Members hold a reference to the team's session_state dict; replacing
the dict would leave them writing to a stale copy. Saved values win,
except for the team-owned runtime keys of the freshly built team.
Source code in src/cs_copilot/agents/session_runs.py
finalize_agno_turn(team, *, failed=False)
¶
Close the ad-hoc tasks delegated during the turn that just ended.
Source code in src/cs_copilot/agents/session_runs.py
reconcile_interrupted_work(run_context)
¶
Close tool spans and tasks left open by a previous process of this chat.
A span recorded by this runtime whose owning process is not this one can no longer finish: the chat server restarted or crashed. It is marked abandoned so it no longer blocks run, task, and artifact transitions, and tasks still marked running are failed as interrupted.
Source code in src/cs_copilot/agents/session_runs.py
store_chat_upload(run_context, *, filename, content)
¶
Write a user upload inside the chat's run and register it as untrusted.
Returns (storage_path, artifact_id). Identical re-uploads reuse the
same content-addressed file and artifact.
Source code in src/cs_copilot/agents/session_runs.py
adopt_session_uploads(run_context, state)
¶
Move uploads stored outside the run (older chats) into it as artifacts.
In enforce mode tools may only read registered artifacts, so uploads that predate the chat's run are copied into it and registered; the original files are left in place.
Source code in src/cs_copilot/agents/session_runs.py
single_agent
¶
Single-agent baseline builder for the multi-agent ablation.
Mirrors :func:cs_copilot.agents.teams.get_cs_copilot_agent_team but returns ONE
flat Agno Agent holding the union of all specialist toolkits. Use the same
Model instance for both this builder and get_cs_copilot_agent_team so the
only variable in the comparison is the agentic structure (single vs multi), not
the base model, tools, or harness.
get_cs_copilot_single_agent(model, *, markdown=True, debug_mode=False, enable_mlflow_tracking=True)
¶
Create the single flat agent (all toolkits, no team, no routing).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
Agno Model instance — pass the SAME instance used for the team so the ablation holds the model constant. |
required |
markdown
|
bool
|
Format output in markdown (matches team members). |
True
|
debug_mode
|
bool
|
Enable debug logs. |
False
|
enable_mlflow_tracking
|
bool
|
Wrap |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
Agent |
Agent
|
The configured single-agent baseline. Exposes |
Agent
|
|
|
Agent
|
either arm through one interface. |
Source code in src/cs_copilot/agents/single_agent.py
teams
¶
Team coordination functionality for multi-agent workflows.
get_cs_copilot_agent_team(model, *, markdown=True, debug_mode=False, show_members_responses=True, enable_memory=True, db_file=None, enable_mlflow_tracking=True, run_context=None, execution_mode=None)
¶
Create a coordinated team of cs_copilot agents using Agno.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
Agno Model instance used for team coordination and member agents |
required |
markdown
|
bool
|
Format output in markdown |
True
|
debug_mode
|
bool
|
Enable debug logs |
False
|
show_members_responses
|
bool
|
Print member responses during coordination |
True
|
enable_memory
|
bool
|
Enable persistent session history (default: True). Cross-session user/agentic memories stay disabled to prevent state leakage. |
True
|
db_file
|
str
|
Custom database file path. If not provided, uses CS_COPILOT_MEMORY_DB. Use unique paths for session isolation in testing. |
None
|
enable_mlflow_tracking
|
bool
|
Enable MLflow tracking for agents (default: True). Set to False to disable tracking. |
True
|
run_context
|
Any
|
Optional v2 workflow |
None
|
execution_mode
|
ExecutionMode | str | None
|
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Team |
Team
|
Configured Cs_copilot team |
Raises:
| Type | Description |
|---|---|
AgentCreationError
|
If one or more agents fail to initialize |
Source code in src/cs_copilot/agents/teams.py
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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |